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 阅读 57 次 更新于 2025-10-31 10:31:19 我来答关注问题0
  •  校企律说法 CSS如何在一个指定范围内让div高度自适应?

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

  • 1、新建一个html文件,创建一个类名为wrap的div。2、先通过css类选择器选择到div来控制div的宽度和高度和背景颜色(没有边框时方便看出来div的大小)。3、通过div 的border属性控制边框颜色,设置border的宽度为2px,线型为实线,颜色为蓝色。4、这样就可以设置div边框颜色宽度和高度,如下图:...

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

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

  • .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 下部DIV...

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

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

CSS相关话题

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