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>
I want the 'view' div to expand to the whole width available after 'tree' div has filled needed space. Currently my 'view' div is resized to content it contains It will also be good if both divs take up whole height
Not duplicate disclaimer:
Expand div to max width when float:left is set because there the left one has a fixed width.
Help with div - make div fit the remaining width because I need two columns both aligned to left
I just discovered the magic of flex boxes (display: flex). Try this:
Flex boxes give me the control I've wished css had for 15 years. Its finally here! More info: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Have a look at the available CSS layout frameworks. I would recommend Simpl or, the slightly more complex, Blueprint framework.
If you are using Simpl (which involves importing just one simpl.css file), you can do this:
, for a 50-50 layout, or :
, for a 25-75 one.
It's that simple.
I wrote a javascript function that I call from jQuery $(document).ready(). This will parse all children of the parent div and only update the right most child.
html
javascript
Use
calc
:The problem with this is that all widths must be explicitly defined, either as a value(px and em work fine), or as a percent of something explicitly defined itself.
Pat - You are right. That's why this solution would satisfy both "dinosaurs" and contemporaries. :)
If the width of the other column is fixed, how about using the
calc
CSS function working for all common browsers:This way the width of the second row will be calculated (i.e. remaining width) and applied responsively.