The red and the green divs are aligned one next to another. How can make the red div be the same height as the green div?
The width property is used to fill a div remaining horizontal space using CSS. By setting the width to 100% it takes the whole width available of its parent. Example 1: This example use width property to fill the horizontal space. It set width to 100% to fill it completely.
The CSS just sizes the div, vertically center aligns the span by setting the div's line-height equal to its height, and makes the span an inline-block with vertical-align: middle. Then it sets the line-height back to normal for the span, so its contents will flow naturally inside the block.
Use absolute positioning and instead of setting the offset with top use bottom . With this property you can ensure the position of the bottom edge of your div - any change in size will force the div to expand upwards. Save this answer.
You should have a div that contains both elements and is clearfixed
<div class="wrapper clearfix">
<div class="red"></div>
<div class="green"></div>
</div>
You then add position relative to the wrapper:
.wrapper {
/* remember this is clearfixed */
position: relative;
}
You let the green container float to the right:
.green {
float: right;
width: 50%;
}
Then you position absolute the red and let it know that it should use all the space of the wrapper:
.red {
position: absolute;
left: 0;
width: 50%;
top: 0;
bottom: 0;
}
Note that this case will only work when the green container is larger than the left one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With