Bài đăng

Đang hiển thị bài đăng từ tháng 12 29, 2014

Vertical Centering With CSS nguồn http://www.vertical-align.com/

Hình ảnh
There are a few ways to center vertically. In terms of block level elements, the methods are quirky. Inline elements are much simpler to center: If you know the height of your containing div, and the height of your inner centered div,  or, if you the height of your inner div does not matter, then vertical aligning is simple.  However, if you are vertically centering anything that is variable, such as text, vertical centering is more complex and require hacks. The HTML used in our examples: <div id="containingBlock"> <div> <p>This sentence will change in each example</p> </div> </div> Note: I will post an entry on vertical centering of text soon Mathematical Method for known heights: When you know the height of the containing element, and the height of the element being vertically centered, simply use math to figure out the height of the margins on the inner element. #containingBlock {display: block; height: 200px;} #contain