html - 如何制作这种布局?(三重嵌套 Div)
问题描述
我在下面制作了一个我想要创建的快速线框图。我只是想将 childDiv 左侧的 25% 突出显示为绿色,将右侧的 65% 突出显示为红色。
我想建立正确的空间,让左 childInnerDiv 为绿色,右 childInnerDiv 为红色。但这似乎不起作用...
我有的:
JsFiddle:http: //jsfiddle.net/8vhgq6k3/
HTML 代码
<div class="ProjectsParentDiv">
<div class="childDiv">
Foo
<div class="childInnerDiv left">
</div>
<div class="childInnerDiv right">
</div>
</div>
<div class="childDiv">
Bar
</div>
<div class="childDiv">
Baz
</div>
</div>
CSS 代码
.ProjectsParentDiv {
// position: relative;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: max-width;
height: 40%;
border: 1px solid black;
}
.childDiv {
display: flex;
background-color: lightblue;
width: 75%;
height: 150px;
margin: 5px auto;
}
.childInnerDiv {
//trying to make the childInnerDiv to be 95% height & width. of the ChildDiv
height: 95%;
width: 95%;
}
.childInnerDiv.left {
flex: 25; //25% of the left side is a div for image.
background: green;
border: 1px solid yellow;
}
.childInnerDiv.right {
flex: 65; //65% of right side is a div for description
background: red;
border: 1px solid silver;
}
解决方案
你可以在下面做。
.ProjectsParentDiv {
// position: relative;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: max-width;
height: 40%;
border: 1px solid black;
}
.childDiv {
align-items: center;
display: flex;;
justify-content: space-around;
background-color: lightblue;
width: 75%;
height: 150px;
margin: 5px auto;
}
.childInnerDiv {
display: flex;
height: 95%;
}
.childInnerDiv.left {
width: 25%;
background-color: green;
border: 1px solid yellow;
}
.childInnerDiv.right {
width: 65%;
background-color: red;
border: 1px solid silver;
}
<div class="ProjectsParentDiv">
<div class="childDiv">
<div class="childInnerDiv left">
</div>
<div class="childInnerDiv right">
</div>
</div>
<div class="childDiv">
Bar
</div>
<div class="childDiv">
Baz
</div>
</div>
推荐阅读
- node.js - 来自节点 azure 函数中请求函数的 context.log 给出警告
- spring-boot - 在 ADFS 服务器上使用 SAML 2.0 的 SSO
- listview - Flutter ListView.Builder Card 小部件占据了屏幕的所有垂直空间
- php - displaying an extra field added to the database in opencart on the order page
- c# - 实体框架作为一个单独的库
- excel - 系统错误“-2147024773 (8007007b)”单击宏按钮时文件名、目录名或卷标语法不正确
- python - 通过 Python-FU 从系统剪贴板创建新图像
- android - 如何获取其他应用程序 Android 的 RAM 使用情况?
- javascript - 如何使用 javascript / node 处理大量数字?
- python - Scrapyd - 即使在 pywin32 安装后,“spawnProcess 不可用,因为未安装 pywin32”