gpt4 book ai didi

html - 左侧 div 侧边栏动态向下延伸到底部

转载 作者:太空宇宙 更新时间:2023-11-04 08:46:24 34 4
gpt4 key购买 nike

我有一个固定宽度 (px) 的左侧边栏,右侧是我的主要内容。

这是我的演示:http://jsfiddle.net/fxWg7/4031/

代码如下:

这是我的 html 代码:

<div class="left">
left content fixed width
</div>
<div class="right">
right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br>
</div>

这是我的 CSS:

.left {
width: 180px;
float: left;
background: #aafed6;
}

.right {
background: #e8f6fe;
width: auto;
overflow: hidden;
}

如何才能使左侧边栏的高度动态拉伸(stretch)到与主要内容相同的长度?

最佳答案

在父级上使用display: flex,两个子级都会拉伸(stretch)以匹配父级的高度。

.container {
height: auto;
overflow: hidden;
display: flex;
}

.left {
width: 180px;
background: #aafed6;
}

.right {
background: #e8f6fe;
}
<div class="container">
<div class="left">
left content fixed width
</div>
<div class="right">
right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br>
</div>
</div>

显示:表格;

.container {
height: auto;
overflow: hidden;
display: table;
width: 100%;
}

.left, .right {
display: table-cell;
}

.left {
width: 180px;
background: #aafed6;
}

.right {
background: #e8f6fe;
}
<div class="container">
<div class="left">
left content fixed width
</div>
<div class="right">
right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible wid
</div>

关于html - 左侧 div 侧边栏动态向下延伸到底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43748747/

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