Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make div expand to occupy available height of parent container

Tags:

html

css

flexbox

I have this code:

html:

<div class="tile">
    <h3>short</h3>
    <div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>

<div class="tile">
    <h3>longLongLong longLongLong longLongLong</h3>
    <div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>

css:

.tile{
    height: 300px;
    width: 200px;
    background: #cecece;
    float: left;
    margin: 0 10px 0 0;
}

.tile h3{
    min-height: 20px;
    max-height: 61px;
    display: inline-block;
    overflow: hidden;
}

.tile .content{
    height: 162px;
    overflow: hidden;
    margin: 0 10px;
}

fiddle:

http://jsfiddle.net/v8Lhxk2v/

and I get this layout

enter image description here

but I need to get something like next image, without using js.

Can that be solved?

enter image description here

like image 321
brabertaser19 Avatar asked Jul 09 '15 23:07

brabertaser19


People also ask

How can I make div occupy full height of container?

Answer: Set the 100% height for parents too And we all know that the default value of the height property is auto , so if we also set the height of <body> and <html> elements to 100%, the resulting height of the container div becomes equal the 100% height of the browser window.

How to make a <Div> fill the height of the remaining space?

How to Make a <div> Fill the Height of the Remaining Space 1. The most usual solution to this problem is to use Flexbox. Let’s see how to use it. For this method, we’ll need the... 2. Another way of making a <div> fill the remaining space is to use the CSS position property. Just set the position ...

How to calculate the height of a Div using CSS?

The last method is to use the CSS calc () function. In this way, we can assign a height calculated from the total height minus the height of the other element. Example of making a <div> fill the remaining space with the calc () function: ¶

How do I set the height of a box in HTML?

Set the height and margin for the <html> and <body> elements. Set the display to “flex”, and add the flex-flow and height properties for the “box” class.

How to increase the height of a pink Div?

If older support is needed, you could add height:100%; to #down will make the pink div full height, with one caveat. It will cause overflow for the container, because #up is pushing it down. Therefore, you could add overflow: hidden; to the container to fix that.


1 Answers

Depending on browser support you can use flex.

The container would need:

display: flex;
flex-flow: column;

Here's a quick demo with example markup:

http://jsbin.com/xuwina/3/edit?html,css,output

like image 115
Bill Criswell Avatar answered Oct 06 '22 09:10

Bill Criswell