Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div to take up entire remaining width [duplicate]

Tags:

css

I have a parent div and 2 divs inside it. First child div is 50px wide and 100% height. Second child div is 100% height and I it to take rest of the width ( 100% - 50px ) how do I do that?

Here is the fiddle that I've created: http://jsfiddle.net/muGty/ Basically I want blue div (right ) to occupy rest of the grey container completely.

<div class="parent">
    <div class="left"></div>
    <div class="right"></div>
</div>
like image 862
sublime Avatar asked May 13 '13 19:05

sublime


2 Answers

Do you mean like this?

<div id="left">
</div>
<div id="right">
</div>

CSS

html, body {
    height: 100%;
}

#left {
    width:200px;
    float:left;
    background: #f00;
    height: 100%;
}
#right {
    margin-left: 200px;
    background: #0f0;
    height: 100%;
}

Update:

You can also use calc() property in CSS3, which will ease up this process like

html, body {
    height: 100%;
}

#left {
    width:200px;
    float:left;
    background: #f00;
    height: 100%;
}

#right {
    float: left;
    background: #0f0;
    height: 100%;
    width: calc(100% - 200px); /* Negate the fixed width element value from 100% */
}

Demo 2

like image 171
Mr. Alien Avatar answered Oct 17 '22 16:10

Mr. Alien


Just change your right div to this:

.right{
    float:left;
    height:50px;
    width: calc(100% - 50px);
    background-color: blue;
    display:inline-block;
}
like image 26
Half_Baked Avatar answered Oct 17 '22 16:10

Half_Baked