Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make div span vertically all available height

Tags:

html

css

enter image description here 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?

like image 681
Ryan Avatar asked Jan 05 '12 09:01

Ryan


People also ask

How do I make a div fill all space available?

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.

How align span vertically in div?

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.

How do I make my div expand upwards?

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.


1 Answers

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.

like image 132
methodofaction Avatar answered Oct 02 '22 14:10

methodofaction