gpt4 book ai didi

html - right-top 和 right-bottom 的高度一起等于左列

转载 作者:太空宇宙 更新时间:2023-11-04 16:14:26 27 4
gpt4 key购买 nike

我已经将右侧的列拆分为顶部和底部。在每个部分中,我在执行以下操作时遇到问题:我希望顶部占据左列高度的 50%,底部占据左列高度的另外 50%。

+-------------------+-------------------+
| | |
| |(right top 50%) |
| | |
|(left column fill) +-------------------+
| | |
| |(right bottom 50%) |
| | |
+-------------------+-------------------+

这是我的html

<div class="container">
<div class="container2">
<div class="left_col">
<div class="right_col">
<div class="right_top">
<div class="right_bottom">
</div>
</div>
</div>
</div>
</div>
</div>

这是我的CSS

.container {
clear: left;
float: left;
width: 95%;
margin: auto;
background-color: #F5F3ED;
color: #333;
overflow: hidden;

}

.container2 {
float: left;
width: 100%;
position: relative;
right: 50%

}

.left_col {
float: left;
width: 60%;
position: relative;
left: 52%;
overflow: hidden;
background-color: #C5D5CB;
padding: 0.5em;
border: 2px solid black;
}

.right_col {
float: left;
width: 30%;
position: relative;
left: 56%;
overflow: hidden;
margin: 0;
padding: .5em;
}



.right_top {
background-color: orange;
height: 50%;
}

.right_bottom {
background-color: green;
height: 50%;
}

最佳答案

Flexbox 可以做到这一点。

* {
box-sizing: border-box;
}
.wrapper {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.left,
.right {
-webkit-box-flex: 0;
-webkit-flex: 0 0 50%;
-ms-flex: 0 0 50%;
flex: 0 0 50%;
border: 1px solid grey;
}

.left {
height: 100px;
}

.right {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.top,
.bottom {
-webkit-box-flex: 1;
-webkit-flex: 1 0 50%;
-ms-flex: 1 0 50%;
flex: 1 0 50%;
border: 1px solid green;
}
<div class="wrapper">
<div class="left"></div>
<div class="right">
<div class="top"></div>
<div class="bottom"></div>
</div>
</div>

关于html - right-top 和 right-bottom 的高度一起等于左列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32997257/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com