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>
|