Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Expand a div to fill the remaining width

I want a two-column div layout, where each one can have variable width e.g.
div {
float: left;
}

.second {
background: #ccc;
}
<div>Tree</div>
<div class="second">View</div>
by

3 Answers

akshay1995
I just discovered the magic of flex boxes (display: flex). Try this:

<style>
#box {
display: flex;
}
#b {
flex-grow: 100;
border: 1px solid green;
}
</style>
<div id='box'>
<div id='a'>Tree</div>
<div id='b'>View</div>
</div>
pankajshivnani123
Use the CSS Flexbox flex-grow property to achieve this.

html, body {
height: 100%;
}
body {
display: flex;
}
.second {
flex-grow: 1;
}


<div style="background: #bef;">Tree</div>
<div class="second" style="background: #ff9;">View</div>
RoliMishra
Use calc:

.leftSide {
float: left;
width: 50px;
background-color: green;
}
.rightSide {
float: left;
width: calc(100% - 50px);
background-color: red;
}

<div style="width:200px">
<div class="leftSide">a</div>
<div class="rightSide">b</div>
</div>

Login / Signup to Answer the Question.