css實現九宮格
阿新 • • 發佈:2017-12-04
http order content image 九宮格 bili back lan osi
原理:浮動+margin負邊距
示例代碼:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>css實現九宮格</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
ul.box {
list-style: none;
width: 165px;
height: 165px;
padding: 30px;
}
.box li {
/*關鍵--浮動*/
float: left;
}
.box a {
display : block;
width: 50px;
height: 50px;
border: 5px solid blue;
/*關鍵--margin負值*/
margin-left: -5px;
/*關鍵--margin負值*/
margin-top: -5px;
}
.box a:hover {
/*關鍵--相對定位*/
position: relative;
border-color: red;
/*關鍵-- z-index*/
z-index: 100;
}
.box:after {
content: "";
height: 0;
visibility: hidden;
clear: both;
display: block;
}
</style>
</head>
<body>
<div id="wrap">
<ul class="box">
<li>
<a href=""></a>
</li>
<li>
<a href=""></a>
</li>
<li>
<a href=""></a>
</li>
<li>
<a href=""></a>
</li>
<li>
<a href=""></a>
</li>
<li>
<a href=""></a>
</li>
<li>
<a href=""></a>
</li>
<li>
<a href=""></a>
</li>
<li>
<a href=""></a>
</li>
</ul>
</div>
</body>
</html>
效果:
鼠標懸浮效果:
css實現九宮格