层叠
样式
表
优先级
浏览器「读」到就生效
selector {
property: value;
/* comments */
}
a:hover {
color: red;
}
选择器 {
属性: 值;
/* 注释 */
}
@charset "UTF-8";
@media screen and (min-width: 480px) {
body {
background-color: #ddd;
}
}
.class
#id
*
element
element,element
element element
:link a:link 选择所有未被访问的链接。
:visited a:visited 选择所有已被访问的链接。
:active a:active 选择活动链接。
:hover a:hover 选择鼠标指针位于其上的链接。
:focus
element>element
element+element
[attribute]
[attribute=value]
[attribute~=value]
[attribute|=value]
element1~element2
:before
:after
匹配规则:从右到左
所有元素可继承:visibility和cursor。
内联元素可继承:letter-spacing、word-spacing、white-space、line-height、color、font、 font-family、font-size、font-style、font-variant、font-weight、text- decoration、text-transform、direction。
块状元素可继承:text-indent和text-align。
列表元素可继承:list-style、list-style-type、list-style-position、list-style-image。
表格元素可继承:border-collapse。
你不需要给每个元素都添加 color: black;
块级元素(block elements)
将窗体自上而下分成一行行, 并在每行中按从左至右的顺序排放元素,即为文档流。
内联元素(inline elements)
inline-block 元素
font-size:12px;
font-size:1.2em;
line-height: 2;
width: 50%;
color: #DDD;
color: #DDDDDD;
color: rgb(55,55,55);
background-image: url(http://....)
font-family: "sans serif";
仅限怪异模式
Floats, absolutely positioned elements, block containers (such as inline-blocks, table-cells, and table-captions) that are not block boxes, and block boxes with 'overflow' other than 'visible' (except when that value has been propagated to the viewport) establish new block formatting contexts for their contents.
In a block formatting context, boxes are laid out one after the other, vertically, beginning at the top of a containing block. The vertical distance between two sibling boxes is determined by the 'margin' properties. Vertical margins between adjacent block-level boxes in a block formatting context collapse.
In a block formatting context, each box's left outer edge touches the left edge of the containing block (for right-to-left formatting, right edges touch). This is true even in the presence of floats (although a box's line boxes may shrink due to the floats), unless the box establishes a new block formatting context (in which case the box itselfmay become narrower due to the floats).
For information about page breaks in paged media, please consult the section on allowed page breaks.