CSS的边界重叠规则
In this specification, the expression collapsing margins means that adjoining margins (no non-empty content, padding or border areas or clearance separate them) of two or more boxes (which may be next to one another or nested) combine to form a single margin.
In CSS 2.1, horizontal margins never collapse.
Vertical margins may collapse between certain boxes:
Two or more adjoining vertical margins of block boxes in the normal flow collapse. The resulting margin width is the maximum of the adjoining margin widths. In the case of negative margins, the maximum of the absolute values of the negative adjoining margins is deducted from the maximum of the positive adjoining margins. If there are no positive margins, the absolute maximum of the negative adjoining margins is deducted from zero. Note. Adjoining boxes may be generated by elements that are not related as siblings or ancestors.
Vertical margins between a floated box and any other box do not collapse (not even between a float and its in-flow children).
Vertical margins of elements that establish new block formatting contexts (such as floats and elements with 'overflow' other than 'visible') do not collapse with their in-flow children.
Margins of absolutely positioned boxes do not collapse (not even with their in-flow children).
Margins of inline-block elements do not collapse (not even with their in-flow children).
If the top and bottom margins of a box are adjoining, then it is possible for margins to collapse through it. In this case, the position of the element depends on its relationship with the other elements whose margins are being collapsed.
If the element's margins are collapsed with its parent's top margin, the top border edge of the box is defined to be the same as the parent's.
Otherwise, either the element's parent is not taking part in the margin collapsing, or only the parent's bottom margin is involved. The position of the element's top border edge is the same as it would have
相关文档:
竞争规则:css允许多次将同一个规则赋予某个元素。层叠排序根据规则中使用的选择符将规则划分6组,高优先级组里的规则会覆盖低优先级组里的规则。普通的选择符会设置文档的总体样式,更具体的选择符会覆盖普通选择符,以为其提供更加特殊的样式
6个选择符群组:
1. 使用!important规 ......
1.css在不同浏览器下显示效果不同
firefox和IE对某些css样式的认定有不少区别,包括:
· ul和ol的默认padding值是不一样的,在Firefox中, ......
#weblmenu
{
height:22px;
width:700px;
float:left;
display:inline;
text-align:left;
}
#weblmenu ul
{
height:22px;
width:700px;
text-align:left;
float:left;
}
#weblmenu ul li
{
height:22px;
width:110px;
float:left;
list-style-type:none;
text-align:center;
word-break:break-all;
} ......
IE6 IE7 IE8 Firefox Opera Google
范例
>
Y
Y
N
N
N
N
.type { >color: #F00; }
.
Y
Y
N
N
N
N
.type { .color: #F00; }
*
Y
Y
N
N
N
N
.type { *color: #F00; }
_
Y
N
N
N
N
N
.type { _color: #F00; }
!important
N
Y
Y
Y
......
.styleName{
color
:
#FFF
;
/* FF,OP,IE8 */
[
;
color:
#0F0
;
]
/* Sa,CH */
*
color
:
#FF0
;
/* IE7 */
_color:
#F00
;
/* IE6 */
}
.styleName{
background-color
:
#332200
;
/* FF*/
}
html*
.styleName{
background-color
:
#FF00FF
;
/* Sa IE7 CH */
}
*+
html .style ......