使用html div css完成五个子层
时间: 2023-08-20 11:05:25 浏览: 42
你可以使用 HTML、CSS 和 `<div>` 元素来创建五个子层。下面是一个示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<style>
/* 设置父层的样式 */
#parent {
width: 200px;
height: 200px;
position: relative;
background-color: #f1f1f1;
}
/* 设置五个子层的样式 */
.child {
position: absolute;
width: 100px;
height: 100px;
}
.child:nth-child(1) {
top: 0;
left: 0;
background-color: red;
}
.child:nth-child(2) {
top: 0;
right: 0;
background-color: green;
}
.child:nth-child(3) {
bottom: 0;
left: 0;
background-color: blue;
}
.child:nth-child(4) {
bottom: 0;
right: 0;
background-color: yellow;
}
.child:nth-child(5) {
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: orange;
}
</style>
</head>
<body>
<div id="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
</body>
</html>
```
以上代码创建了一个父层 `<div>`,并在其中嵌套了五个子层 `<div>`。每个子层都使用了绝对定位(`position: absolute;`)来使其脱离文档流,并通过 `top`、`right`、`bottom` 和 `left` 属性来确定其位置。子层的样式可以根据自己的需求进行修改。