CSS中DIV高度的设置?

border-box ; } .A { height: 100px; margin: -100px 0 0; background: #BBE8F2; } .B { height: 100%; background: #D9C666; } 头部DIV 下部DIV 代码效果 你可以看下效果,望采纳。
CSS中DIV高度的设置?
html,
body { height: 100%; padding: 0; margin: 0; }
.mother { height: 100%; padding: 100px 0 0; box-sizing: border-box ; }
.A { height: 100px; margin: -100px 0 0; background: #BBE8F2; }
.B { height: 100%; background: #D9C666; }

<div class="mother">
<div class="A">头部DIV</div>
<div class="B">下部DIV</div>
</div>

代码效果
你可以看下效果,望采纳。
2021-09-06
html代码:
<div class="container">
<div class="up"></div>
<div class="down"></div>
</div>
css代码:
<style>
.container{
background-color: lightblue;
width: 500px;
height: 700px;

}
.up{
width: 100%;
height: 200px;
background-color: lightcoral;
}
.down{
width: 200px;
height: auto;
}
</style>

下面的div高度设为auto就行,会自动占满整个父容器剩余的高度2021-12-01
<style>
*{
margin: 0;
padding: 0;
}
body {
width: 100vw;
height: 100vh;
}
.mother {
height: 100%;
width: 100%;
}

.A {
height: 100px;
background: #BBE8F2;
}

.B {
height: calc(100% - 100px);
background: #D9C666;
}
</style>

<div class="mother">
<div class="A">头部DIV</div>
<div class="B">下部DIV</div>
</div>
或者使用 grid 布局:
<style>
*{
margin: 0;
padding: 0;
}
body {
width: 100vw;
height: 100vh;
}
.mother {
height: 100%;
width: 100%;
display: grid;
grid-template-rows: 100px 1fr;
}

.A {
background: #BBE8F2;
}

.B {
background: #D9C666;
}
</style>2021-09-16
mengvlog 阅读 38 次 更新于 2025-09-10 05:06:29 我来答关注问题0
  •  校企律说法 CSS如何在一个指定范围内让div高度自适应?

    要使一个的高度在指定范围内自适应内容,可以使用CSS中的min-height和max-height属性。具体来说,可以设置min-height为100px,max-height为500px。这样,的高度将至少为100px,但不会超过500px。当内容超出100px但未达到500px时,的高度将根据内容自动调整。此外,为了实现更灵活的高度自适应,可以结合使用...

  •  猪八戒网 div设置高度自适应?

    示例代码如下:CSS代码第一种写法 html,body{height:100%;margin:0;}/**把HTML和BODY的高度设置成100%**/ div{height:100%;background-color:#ccc;}/**把你DIV的高度设置成100%**/ CSS代码第二种写法 div{height:100%;position:absolute;width:100%;background-color:#ccc;left:0;top:0;}...

  •  宜美生活妙招 如何让div高度自适应

    方法说明:这种方法不是真正的自适应高度,而是设置一个足够高的默认值,以确保在大多数情况下都能覆盖内容。同时,通过CSS的overflow属性来处理溢出部分。实现方式:为div设置一个相对较高的height值,并使用overflow: hidden;(或auto,根据需要)来处理内容溢出。这种方法虽然简单,但不够灵活,可能不适用...

  •  校企律说法 CSS默认下固定高度,自动适应

    在CSS中,我们经常遇到这样的需求:设定一个容器的最小高度,同时让其根据内容自动调整高度。例如,对于一个div元素,我们可以通过以下CSS代码实现这一效果:div{ min-height:400px; height:auto;} 具体来说,这里做了两件事:首先,我们设定了元素的最小高度为400像素。这意味着,无论内容多少,元素...

  • 在网页设计中,我们经常需要让元素的宽度和高度根据浏览器窗口大小自适应调整。这可以通过CSS的百分比单位来实现。具体来说,设置的宽度和高度属性为100%,可以让它们跟随浏览器窗口的宽度和高度进行调整。假设我们有一个未添加任何CSS样式的元素,我们可以直接在HTML代码中定义一个空的标签,如下所示:

檬味博客在线解答立即免费咨询

CSS相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部