通常,对于这种设计,最好使用HTML标记,该标记将容器拆分为多行,但也可以使用flexbox,如下面建议的解决方案所示。
由于我们试图保留您使用的标记,为了在您的图像中创建居中框,我们必须将其从流中取出,然后使用以下方法居中:
-
position: absolute
-
top: 50%
,
-
left: 50%
和
-
transform: translate(-50%, -50%)
.
.container {
width: 240px;
height: 240px;
display: flex;
flex-wrap: wrap;
position: relative;
margin: 10px auto;
}
.box {
color: #fff;
height: 120px;
width: 120px;
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0 10px;
background-color: #70ad47;
border: 1px solid #fff;
}
.box.top-row {
align-items: flex-start;
}
.box.bottom-row {
align-items: flex-end;
}
.box > p {
text-align: center;
}
#tl-box {
border-top-left-radius: 10px;
}
#tr-box {
border-top-right-radius: 10px;
}
#bl-box {
border-bottom-left-radius: 10px;
}
#br-box {
border-bottom-right-radius: 10px;
}
#cc-box {
color: #0c0e0c;
height: 50%;
width: 50%;
position: absolute;
top: 50%;
left: 50%;
background-color: #bbd3b1;
border: 2px solid #fff;
border-radius: 10px;
transform: translate(-50%, -50%);
}
<h2 align = "center">PI Graphs</h2>
<div class = "container">
<div id = "tl-box" class = "box top-row">
<p>Locations Counted</p>
</div>
<div id = "tr-box" class = "box top-row">
<p>Locations Accurate</p>
</div>
<div id = "bl-box" class = "box bottom-row">
<p>Serial Not Exist</p>
</div>
<div id = "br-box" class = "box bottom-row">
<p>Serials Wrong Location</p>
</div>
<div id = "cc-box" class = "box">
<p>Current Days Accuracy 98%</p>
</div>
</div>