工作中常用的高效的CSS代码
点击次数:35 次 发布日期:2008-11-21 16:00:53 作者:源代码网
|
源代码网推荐
源代码网整理以下我们最常用的有四种选择方法,
源代码网整理以下Id规则选取,比如
源代码网整理以下
| 以下为引用的内容:
源代码网整理以下button#button{} #urlBar[type=”text”] { } div > p > span#demo{}
|
源代码网整理以下class规则选取,比如
| 以下为引用的内容:
源代码网整理以下button.toolbarButton { } .fancyText { } menuitem > .menu-left[checked=”true”] { }
|
源代码网整理以下Tag规则选取,比如
源代码网整理以下
| 以下为引用的内容:
源代码网整理以下td { } div > p { } input[type=”checkbox”] { }
|
源代码网整理以下统配选择器,比如
源代码网整理以下
| 以下为引用的内容:
源代码网整理以下* :after [hidden=”true”]
|
源代码网整理以下他们都是从最右边开始匹配,直到最左边整个规则结束。 这样就存在一个问题,比如说最右边的规则已经能确定你要选取到元素。 那更多的规则匹配就造成了性能上的浪费。 比如说div > p > span#demo{} div > p > span根本没有意义。
源代码网整理以下改进: ID是唯一的。没有必要附加多余的规则。也能精准的匹配到。
源代码网整理以下
| 以下为引用的内容:
源代码网整理以下button#button{} -> #button{} #urlBar[type=”text”] { } -> #urlBar{} div > p > span#demo{} -> #demo{}
|
源代码网整理以下下面应该不会出现<a class=”toolbarButton”></a>所以也可以优化。
源代码网整理以下
|
源代码网整理以下以下为引用的内容:
源代码网整理以下button.toolbarButton { } -> .toolbarButton{}
|
源代码网整理以下用过多的规则,不如直接给元素一个class 比如:div > p > span > a{} 可能给a一个特殊表现的。直接给a写一个class即可。 特殊情况需要特殊对待。 比如有时候要保证页面结构的干净。以便适用后期改版的需要,使用到这种方式。也是可以的。平衡取出一个最佳方案。
源代码网整理以下使用继承 #demo .left{text-align:left} ->#demo{text-align:left} 注:原文中使用的XUL.对没接触过XUL的同学,可能标签看起来有点怪,但不难理解。
源代码网供稿. |