选择器
<!DOCTYPE html>
<html lang="en">
<head>
<title>Direct</title>
<style>
body {
margin: 0;
padding: 0;
background-color: rgb(59, 58, 58);
color: white;
font-family: Helvetica Neue,Arial, sans-serif;
}
ul {
list-style: none;
padding: 0;
}
li {
display: inline-block;
margin-left: 20px;
border-radius: 3px;
padding: 2px;
background-color: gray;
}
li:hover{
background-color: indianred;
}
li:active{
text-decoration: underline;
}
li:first-child {
margin-left: 0;
background-color: red;
}
a{
text-decoration: none;
}
a:hover{
text-decoration: underline;
}
.feature-box {
display: flex;
text-align: center;
}
.feature-box div{
width: 100%;
margin: 1px;
}
.feature-box.sales div {
background-color: gray;
}
.feature-box.closeouts div {
background-color: red;
}
#seldom {
font-size: 150%;
}
</style>
</head>
<body>
<header>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Locations</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Directions</a></li>
</ul>
</header>
<section class="feature-box sales">
<div>section a</div>
<div>section b</div>
<div>section c</div>
</section>
<section id="seldom" class="feature-box closeouts">
<div>section d</div>
<div>section e</div>
</section>
</body>
</html>
Tips
- 伪类的使用很有趣,除了可以指定child,来特指一类中的特别元素,还可以通过hover,active来实现一些交互。
- 多类,通过空格隔开,可以通过相同的类名设定相同的样式,在通过不同的类名设定特别的样式,减少了代码的冗余程度