CSS3 继承的技巧

稍不留意便会忽略掉级联样式表的特点。大多数开发者都知道inherit关键字,但有几个新的CSS3继承特性你可能不知道…

property: inherit;

inherit关键字代表“使用指定给父元素的所有值”。如果父元素中没有明确的值定义,浏览器搜寻DOM树直到找到相应的属性。最终无法找到的话,它会使用浏览器的默认值,例如:

1
2
3
4
5
6
7
8
9
10
11
#myparent
{
    margin10px;
    border1px solid #000;
}
/* use the same border as the parent */
#myparent p
{
    border: inherit;
}

继续阅读