Css 如何以最大高度放置第一个div?

Css 如何以最大高度放置第一个div?,css,Css,我有一个div“.container”和两个div:第一个“.blue”,第二个“.green”。 我让我的绿色球固定在底部0,但我需要把第一个蓝色球放在绿色球的篮板上 css: html: 蓝色 绿色 您可以将两个div都设置为绝对位置,然后使用您需要执行的任何操作: .container{ position: relative; width: 100%; } .blue, .green { position: absolute; width: 100

我有一个div“.container”和两个div:第一个“.blue”,第二个“.green”。 我让我的绿色球固定在底部0,但我需要把第一个蓝色球放在绿色球的篮板上


css:


html:


蓝色
绿色

您可以将两个div都设置为绝对位置,然后使用您需要执行的任何操作:

.container{
    position: relative;
    width: 100%;
}

.blue,
.green {
    position: absolute;
    width: 100%;
    top: 0;
    left: 0;
    height: 250px;
}

.blue{    
    background-color: #bbf;
}

.green{ 
    background-color: #bfb;
    top: 250px;
}
俯冲


Divs重叠

您想要这样的吗?还是像这样?你说的篮板是什么意思?作为背景?如果您希望蓝色
div
获取可用高度,请使用
calc
,如果您希望它获取所有高度(包括绿色div后面的高度),可以添加use
html、body、.container、.blue{height:100%;}
您可以通过将
.green
不透明度设置为
0.5
进行测试。
<!-- some divs before -->
<div class="container">
    <div class="blue">Blue</div>
    <div class="green">Green</div>
</div>
.container{
    position: relative;
    width: 100%;
}

.blue,
.green {
    position: absolute;
    width: 100%;
    top: 0;
    left: 0;
    height: 250px;
}

.blue{    
    background-color: #bbf;
}

.green{ 
    background-color: #bfb;
    top: 250px;
}