1. Outline(适用范围:鼠标悬浮hover加外边框)html
咱们在布局的时候,经常会由于添加边框border影响宽高的布局。浏览器
那么,outline是完美的替代品,由于它能够在不影响文档流的状况下呈现该对象。可是IE6 和IE7 不支持 outline 属性。因此,它不能在这两个浏览器中用于调试。布局
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
ul {
width: 500px;
margin: 50px auto;
list-style: none;
}
li {
width: 100px;
height: 100px;
background: #ececec;
float: left;
margin-right: 10px;
}
li:hover {
background: pink;
/*border: 2px solid red; */ /*border能够兼容到任何浏览器*/
outline: 2px solid red; /*outline只有IE6和IE7不支持此属性*/
}
</style>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</body>
2. first-child(第一个元素)、last-child(最后一个元素)、nth-child(*) (第*个元素) (适用范围:块级元素中有相同的元素)post
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
<head>
<meta charset=
"UTF-8"
>
<title>Title</title>
<style>
ul {
width: 500px;
margin: 50px auto;
list-style: none;
}
li {
width: 100px;
height: 100px;
float
: left;
margin-right: 10px;
}
li:first-child {
background: pink;
}
li:last-child {
background: green;
}
li:nth-child(2) {
background: red;
}
li:nth-child(3) {
background: yellow;
}
</style>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</body>
|