CSS實例:圖片導航塊
阿新 • • 發佈:2017-10-20
static -1 ctype char ext .com style 學生 stat
- 認識CSS的 盒子模型。
- CSS選擇器的靈活使用。
- 實例:
- 圖片文字用div等元素布局形成HTML文件。
- 新建相應CSS文件,並link到html文件中。
- CSS文件中定義樣式
- div.img:border,margin,width,float
- div.img img:width,height
- div.desc:text-align,padding
- div.img:hover:border
- div.clearfloat:clear
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>img</title>
<link rel="stylesheet" type="text/css" href="../static/css/img.css">
</head>
<body>
<div class="recommend">
<div class="img">
<a href="http://www.gzcc.cn"><img src="http://www.gzcc.cn/2016/images/yhdh/01.jpg"></a>
<div class="desc"><a href="http://www.gzcc.cn">校園風光</a></div>
</div>
<div class="img">
<a href="http://www.gzcc.cn"><img src="http://www.gzcc.cn/2016/images/yhdh/02.jpg"></a>
<div class="desc"><a href="http://www.gzcc.cn">校園文化</a></div>
</div>
<div class="img">
<a href="http://www.gzcc.cn"><img src="http://www.gzcc.cn/2016/images/yhdh/06.jpg"></a>
<div class="desc"><a href="http://www.gzcc.cn">校園歷史</a></div>
</div>
<div class="img">
<a href="http://www.gzcc.cn"><img src="http://www.gzcc.cn/2016/images/yhdh/07.jpg"></a>
<div class="desc"><a href="http://www.gzcc.cn">學生活動</a></div>
</div>
</div>
<div class="clearfloat">
<a href="http://www.gzcc.cn"><img src="http://www.gzcc.cn/2016/images/yhdh/04.jpg"></a><br>
<img src="http://www.gzcc.cn/2016/images/yhdh/01.jpg"><br>
<img src="http://www.gzcc.cn/2016/images/yhdh/02.jpg"><br>
<img src="http://www.gzcc.cn/2016/images/yhdh/06.jpg"><br>
<img src="http://www.gzcc.cn/2016/images/yhdh/07.jpg"><br>
</div>
</body>
</html>
img {
width: 300px;
}
div.img {
berder: 1px solid #ccc;
width: 200px;
float: left;
margin: 5px;
}
div.img img {
width: 100%;
height: auto;
}
div.desc {
text-align: center;
padding: 5px;
}
div.img:hover {
border: 1px solid #000000;
}
div clearfloat {
clear: both;
}
CSS實例:圖片導航塊