Showing posts with label auto. Show all posts
Showing posts with label auto. Show all posts

Wednesday, March 05, 2008

CSS inline-box and auto margin

line-height只对内联元素有效,对于块元素设置其实是作用在其内部的内联元素上。
水平七属性中margin-left、margin-right、width的值可以设置为auto,其他四个属性不能设置为auto。
水平七属性相加的值总是等于其父元素的width值。
margin的值可以取负值,padding和width不能取负值。
一行中,不同内联元素的内联框位置并不一定相同,根据line-hight、font-size计算,并受vertical-align影响。以下公式在vertical-align基于baseline的计算方法:
内联框的上边框位置:font-size - (font-size - line-height) / 2
内联框的下边框位置:font-size + (font-size - line-height) / 2
行间距等于该行中所有内联元素的内联框(inline-box)的最高位置减最低位置。

Sunday, February 24, 2008

[CSS Zen Garden]Centered Design Using Auto Margins

The preferred way to horizontally center any element is to use the margin property and set left and right values to auto. For this to work with layouts, you'll create a containing div. You must include a width for your containing div:

div#container {
margin-left: auto;
margin-right: auto;
width: 168px;
}