1 回答
TA贡献1847条经验 获得超7个赞
试试用 text-align: justify;吧,宽度不用写死,百分比也行,其实还是比较推荐用js控制计算的,.mybox的padding可以用calc计算,当然你要兼容ie8还是用js计算吧
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.mybox{
width: 800px;
border: 1px solid #000000;
height: 500px;
text-align: justify;
text-justify: inter-ideograph;
padding: 100px;
}
.mybox:after{
content: '';
width: 100%;
position: relative;
display: inline-block;
}
.mybox .box{
width: 12.5%;
background: red;
display: inline-block;
position:relative;
}
.box:before{
content: '';
padding-top: 100%;
box-sizing: border-box;
display: block;
width: 0;
}
.pox{
position:absolute;
height:100%;
width:100%;
left: 0;
top: 0;
border: 1px solid red;
box-sizing: border-box;
}
</style>
</head>
<body>
<body >
<div class="mybox">
<div class="box"><div class="pox"></div></div>
<div class="box"><div class="pox"></div></div>
<div class="box"><div class="pox"></div></div>
<div class="box"><div class="pox"></div></div>
<div class="box"><div class="pox"></div></div>
</div>
</body>
</body>
</html>
添加回答
举报