gpt4 book ai didi

jquery - 如何使彼此相邻的两个 div 具有相同的高度?

转载 作者:行者123 更新时间:2023-11-28 01:34:20 25 4
gpt4 key购买 nike

所以我写了一个包含三个 div 的 Web 应用程序。一个用于左侧那个下方的标题,并带有菜单和将加载内容的菜单旁边。

所以我不想设置静态宽度和内容长度变化。我试过 overflow:auto但这没有用。

CSS:

body {
margin: 0;
padding:0;
height:100%;
}

.area-header {
height:40px;
background-color:#71A4C3;
margin-bottom: 20px;
margin-left:20px;
margin-right:20px;
}

.area-menu {
width:300px;
margin-left:20px;
background-color:#8BC6EA;
display:inline-block;
margin-bottom:auto;
padding-bottom:100%;
height:100%;
}

.area-content {
display:inline-block;
position:absolute;
margin-right:20px;
margin-left:20px;
}

HTML:

<body>
<div id="area-header" class="area-header">
<h2>A Web Application!</h2>
</div>

<div id="area-menu" class="area-menu">
<ul id="menu">
@foreach (WebApplicationWithSqlAndJS.Models.MenuItem item in Model)
{
<li id="menu-item"><a href="@item.Target" onclick="return false">@item.Title</a></li>
}
</ul>
</div>

<div id="area-content" class="area-content"></div>

</body>

最佳答案

你只需要添加一个父 div 到你想要有相同高度的 div。

父级:

溢出:隐藏;

子元素:

float :左;填充底部:500em; margin 底部:-500em;


You can get equal height columns in CSS by applying bottom padding of a large amount, bottom negative margin of the same amount and surrounding the columns with a div that has overflow hidden. Vertically centering the text is a little trickier but this should help you on the way.

https://stackoverflow.com/a/1205485/2851845


   
body
{
margin: 0;
}

.area-header
{
height:40px;
background-color:#71A4C3;
margin-bottom: 20px;
margin-left:20px;
margin-right:20px;
}

#area-wrapper
{
overflow: hidden;
width: 100%;
}

.area-menu, .area-content
{
float:left;
padding-bottom: 500em;
margin-bottom: -500em;
}

.area-menu
{
width: 200px;
background-color:#8BC6EA;
}

.area-content
{
width: 400px;
background-color: LightSlateGrey;
}
<body>
<div id="area-header" class="area-header">
<h2>A Web Application!</h2>
</div>
<div id="area-wrapper">
<div id="area-menu" class="area-menu">
<ul id="menu">
<li id="menu-item"><a href="#" onclick="return false">@item.Title</a></li>
</ul>
</div>
<div id="area-content" class="area-content">
<div style="height:200px;background:red;"></div>
</div>
</div>
</body>

关于jquery - 如何使彼此相邻的两个 div 具有相同的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29032782/

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