白天 |  黑夜

CSS中级教程 组合与嵌套

船长 发表于 2009-06-18 10:11 | 分类:css | 阅读数:901 次

组合

你不必重复有相同属性的多个选择符,你只要用英文逗号(,)隔开选择符就可以了。
比如,你有如下的代码:

Example Source Code
h2 { 
color: red; 

.thisOtherClass { 
color: red; 

.yetAnotherClass { 
color: red; 

则你可以这样写:

Example Source Code
h2, .thisOtherClass, .yetAnotherClass { 
color: red; 

嵌套

CSS结构好的话,没有必要使用过多的类或者标识选择符。这是因为你可以指定在选择符内的选择符。(或者更好的说法,上下文选择符–译者著)
比如:

Example Source Code
#top { 
background-color: #ccc; 
padding: 1em 

#top h1 { 
color: #ff0; 

#top p { 
color: red; 
font-weight: bold; 

这就减去不必要的类或者标识选择符,如果应用到像这样的HTML中:

Example Source Code
<div id=”top”> 
<h1>Chocolate curry</h1> 
<p>This is my recipe for making curry purely with chocolate</p> 
<p>Mmm mm mmmmm</p> 
</div> 
本站QQ交流群:16524922,一起交流学习,互帮互助
转载请注明出处:http://www.songlecn.com/2009/06/1131/
我要评论 标签: ,
上一篇
下一篇
喜欢web集结号的文章,那就通过 RSS Feed 功能订阅阅读吧!

我要评论

* 必填

* 绝不会泄露


Css Tutorials

web集结号致力于

  • Css技巧及模板
  • Javascript技巧及特效
  • JQuery插件及应用
  • 建站图片资源
  • 网络休闲及生活感悟