绝对布局怎么水平居中
不同屏幕尺寸下,绝对布局,这个问题困扰了我很久,先分享我摸索的方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.imgs{
/* 相对于.imgs */
position: relative;
}
.img{
width: 100%;
}
img {
width: 100%;
}
.bar span{
display: inline-block;
list-style: none;
width: 2px;
height: 2px;
border-radius: 50%;
border: 1px solid #555555;
background: #555555;
}
.bar_outer {
/* 绝对布局,相对于.imgs */
position: absolute;
bottom: 10px;
width: 100%;
}
.bar{
/* 关键代码!! */
margin: auto;
display: block;
text-align: center;
}
</style>
</head>
<body>
<div class="imgs">
<div class="img">
<img src="https://via.placeholder.com/360x360.png" />
</div>
<div class="bar_outer">
<span class="bar">
<span></span>
<span></span>
<span></span>
<span></span>
</span>
</div>
</div>
</body>
</html>
下面就是效果:底部的几个小圆点无论屏幕有多大都会居中显示了