用HTML+CSS画出一个长方形容器,里面包含一个小一点的长方形分成三格,距离外部的长方形边框5px,分别在长方形的上下左右标识出每条边的长度
时间: 2024-05-10 12:13:40 浏览: 204
好的,让我帮您实现一下:
HTML:
```
<div class="container">
<div class="inner-container">
<div class="grid"></div>
<div class="grid"></div>
<div class="grid"></div>
</div>
</div>
```
CSS:
```
.container {
width: 200px;
height: 150px;
border: 5px solid #000;
padding: 0 10px;
}
.inner-container {
width: 100%;
height: 100%;
display: flex;
justify-content: space-between;
}
.grid {
width: calc(33.33% - 5px);
height: 100%;
border: 2px solid #000;
}
.grid:first-child {
border-right: none;
}
.grid:last-child {
border-left: none;
}
.grid:nth-child(2) {
border-top: none;
}
.grid:last-child:not(:nth-child(2)) {
border-bottom: none;
}
.container::before,
.container::after {
content: "";
position: absolute;
left: 5px;
}
.container::before {
top: 5px;
border-top: 1px solid #000;
width: calc(100% - 10px);
}
.container::after {
bottom: 5px;
border-bottom: 1px solid #000;
width: calc(100% - 10px);
}
.container::before,
.container::after,
.grid:first-child {
border-left: 1px solid #000;
}
.container::before,
.container::after,
.grid:last-child {
border-right: 1px solid #000;
}
```
这样,一个长方形容器,里面分成三个网格的效果就实现了,您可以在页面中看到标识出每条边的长度。感谢您的提问。
阅读全文