gpt4 book ai didi

html - HTML 中两个面板布局的容器高度

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

两个面板布局的外部容器不会垂直拉伸(stretch)。

<DIV>带有 id 容器的是两个面板的两个 DIV:

  • <DIV>侧边栏是左面板
  • <DIV>内容是右面板

当侧边栏比内容长时,外部容器不会拉伸(stretch)。

<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<meta charset="utf-8">
<style>
#container {
width: 600px;
border: 1px solid blue;
}

#content {
border: 2px dashed red;
margin-left: 220px;
margin-right: 10px;
}

#sidebar {
float: left;
border: 2px dashed green;
width: 200px;
margin-right: 10px;
margin-left: 10px;
}
</style>
</head>
<body>
<div id="container">
<div id="sidebar">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Proin nibh augue, suscipit a, scelerisque sed, lacinia in, mi.
Cras vel lorem. Etiam pellentesque aliquet tellus.
</div>
<div id="content">
Article with some content. Article with some content. Article with some content.
</div>
</div>
</body>
</html>

so-example-html-two-panel-outer-container-not-stretched

最佳答案

为容器使用 overflow css 属性。这将自动调整其高度。 Documentation on overflow .

使用下面的代码。

<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<meta charset="utf-8">
<style>

#content {
border: 2px dashed red;
margin-left: 220px;
margin-right: 10px;
}

#sidebar {
float: left;
border: 2px dashed green;
width: 200px;
margin-right: 10px;
margin-left: 10px;
}
#container {
width: 600px;
overflow: hidden;
border: 1px solid blue;
}

</style>
</head>
<body>
<div id="container">
<div id="sidebar">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Proin nibh augue, suscipit a, scelerisque sed, lacinia in, mi.
Cras vel lorem. Etiam pellentesque aliquet tellus.
</div>
<div id="content">
Article with some content. Article with some content. Article with some content.
</div>
</div>
</body>
</html>

关于html - HTML 中两个面板布局的容器高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36821566/

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