CSS 定位盒子居中对齐
2018-12-11 本文已影响21人
roy_pub
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
margin: 0;
padding: 0;
}
div {
width: 520px;
height: 280px;
margin: 20px auto;
position: relative;
}
.leftDot {
width: 24px;
height: 36px;
position: absolute;
top: 50%;
margin-top: -18px;
background: url("images/left.png") no-repeat;
}
.rightDot {
width: 24px;
height: 36px;
position: absolute;
right: 0;
top: 50%;
margin-top: -18px;
background: url("images/right.png") no-repeat;
}
ul {
width: 70px;
height: 14px;
background-color: rgba(255,255,255,0.5);
border-radius: 8px;
position: absolute;
bottom: 20px;
left: 50%;
margin-left: -35px;
}
li {
float: left;
list-style: none;
width: 8px;
height: 8px;
border-radius: 4px;
background-color: white;
margin: 3px;
display: inline-block;
}
</style>
</head>
<body>
<div>
<img src="images/taobao.jpg" height="280" width="520"/>
<a href="#" class="leftDot"></a>
<a href="#" class="rightDot"></a>
<div class="bottomDot"></div>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
margin: 0;
padding: 0;
}
.sf {
width: 1259px;
height: 472px;
margin: 0 auto;
position: relative;
}
.nav {
width: 960px;
height: 80px;
background-color: #000;
position: absolute;
bottom: 0;
left: 50%;
margin-left: -480px;
}
.nav li {
float: left;
width: 160px;
height: 80px;
list-style: none;
line-height: 80px;
}
.nav li a {
text-align: center;
text-decoration: none;
display: block;
color: white;
}
.nav li a:hover {
color: #000;
background-color: #fff;
}
</style>
</head>
<body>
<div class="sf">
<a href="#">
<img src="images/sf.png" height="472" width="1259"/>
</a>
<div class="nav">
<ul>
<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>
</div>
</body>
</html>