CSS的class以及id选择器

来自http://tunps.com/css-class-and-id-selector

前面的学习我们仅仅使用HTML选择器(在HTML页面里为html标签,如 P)
现在我们学习使用clss和id定义属于自己的选择器。
这样,同样的html元素可以通过class或ID使用不同的表现。
在CSS里,使用点号(.)创建class选择器,使用hash符号(#)创建ID选择器。
例子:

#top {
background-color: #ccc;
padding: 1em
}
.intro {
color: red;
font-weight: bold;
}

html页面通过id和class属性调用CSS,像下面这样:

<div id="top">
<h1>Chocolate curry</h1>
<p class="intro">This is my recipe for making curry purely with chocolate</p>
<p class="intro">Mmm mm mmmmm</p>
</div>

id和class的不同指出在于一个页面同一个ID只能只有一次,而class可以无限制使用。
同样,你可以在html选择器后面使用一个选择器来指定特殊HTML元素,比如p.jam{值}将作用到带有'jam'class属性的段落。

About tunpishuang

just 4 fun·····
This entry was posted in 未分类 and tagged . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>