CSS实例:图片导航块
<!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <link rel="stylesheet" href="../static/css/1020.css"> 7 </head> 8 <body> 9 <div> 10 <div class="img"> 11 <a href="http://www.gzcc.cn/"><img src="http://5.66825.com/download/pic/000/330/78bf0024619714bdd091e5766af09e8f.jpg"></a> 12 <div class="desc"><a href="http://www.gzcc.cn/">我是链接1</a></div> 13 </div> 14 15 <div class="img"> 16 <a href="http://www.gzcc.cn/"><img src="http://tupian.enterdesk.com/2013/lxy/09/14/1/7.jpg"></a> 17 <div class="desc"><a href="http://www.gzcc.cn/">我是链接2</a></div> 18 </div> 19 20 <div class="img"> 21 <a href="http://www.gzcc.cn/"><img src="http://tupian.enterdesk.com/2013/lxy/09/14/1/8.jpg"></a> 22 <div class="desc"><a href="http://www.gzcc.cn/">我是链接3</a></div> 23 </div> 24 25 <div class="img"> 26 <a href="http://www.gzcc.cn/"><img src="http://img.kumi.cn/photo/ed/92/c1/ed92c1873c571362.jpg"></a> 27 <div class="desc"><a href="http://www.gzcc.cn/">我是链接4</a></div> 28 </div> 29 <div class="clearfloat"> 30 <img src="http://5.66825.com/download/pic/000/330/78bf0024619714bdd091e5766af09e8f.jpg"><br>
31 <img src="http://tupian.enterdesk.com/2013/lxy/09/14/1/7.jpg"><br>
32 <img src="http://tupian.enterdesk.com/2013/lxy/09/14/1/8.jpg"><br>
33 <img src="http://img.kumi.cn/photo/ed/92/c1/ed92c1873c571362.jpg">
34 </div>
35
36 </div>
37 </body>
38 </html>
img {
2 width: 300px;
3 }
4
5 div.img {
6 width: 180px;
7 border: 1px solid #ccc;
8 float: left;
9 margin: 5px;
10 }
11
12 div.img img {
13 width: 180px;
14 height: auto;
15 }
16
17 div.img:hover {
18 border: 3px solid #DCDCDC;
19
20 }
21
22 div.desc {
23 text-align: center;
24 padding: 5px;
25 }
26
27 a {
28 text-decoration: none; /*去除a标签下划线*/
29 color: brown; /*链接文本颜色为红色*/
30 }
31
32 a:hover {
33 text-decoration: underline;/*鼠标移到链接会有下划线*/
34 }
35
36 .clearfloat {
37 clear: both;
38 }