CSS .class 选择器
Select and style all elements with class="intro":
<!DOCTYPE html>
<html>
<head>
<style>
.intro {
background-color: yellow;
}
</style>
</head>
<body>
<h1>Welcome to My Homepage</h1>
<div class="intro">
<p>My name is Donald.</p>
<p>I live in Duckburg.</p>
</div>
<p>My best friend is Mickey.</p>
</body>
</html>
定义和用法
The .class选择器是指定类的所有元素的样式。
Browser Support
![]()
![]()
![]()
![]()
![]()
所有主流浏览器都支持.class选择器
更多实例
Style all <p> elements with class="hometown":
<!DOCTYPE html>
<html>
<head>
<style>
p.hometown {
background: yellow;
}
</style>
</head>
<body>
<p>My name is Donald.</p>
<p class="hometown">I live in Ducksburg.</p>
<p>My name is Dolly.</p>
<p class="hometown">I also live in Ducksburg.</p>
</body>
</html>
完整CSS选择器参考手册