<div id="sidebar">sidebar</div>
<div id="content">content</div>
The sidebar is a fixed width of 100px. How do I make the width of content to 100% of the browser width?
http://jsfiddle.net/chickendance/qQQTU/1/
If you want a block-level element to fill any remaining space inside of its parent, then it's simple — just add width: 100% in your CSS declaration for that element, and your problem is solved.
So, by nature, it doesn't matter how much content the element contains because its width is always 100%, that is, until we alter it. Think of elements like <p> , <article> , <main> , <div> , and so many more.
Try setting the height of the html element to 100% as well. Body looks to its parent (HTML) for how to scale the dynamic property, so the HTML element needs to have its height set as well. However the content of body will probably need to change dynamically. Setting min-height to 100% will accomplish this goal.
You can do this with simple CSS:
#sidebar {
float: left;
width: 100px;
}
#content {
margin-left: 100px;
}
Updated with wrapper
div:
HTML
<div id="wrapper">
<p>wrapper</p>
<div id="sidebar">sidebar</div>
<div id="content">content</div>
<p>wrapper</p>
</div>
CSS
* {
/* reset */
margin: 0;
padding: 0;
}
html,
body {
/* for demo purposes only */
height: 100%;
}
#wrapper {
/* for demo purposes only */
background: rgba(200, 200, 200, 0.6);
height: 100%;
}
#sidebar {
float: left;
width: 100px;
/* for demo purposes only */
background: rgba(200, 200, 200, 0.6);
height: 50%;
}
#content {
margin-left: 100px;
/* for demo purposes only */
background: rgba(200, 200, 200, 0.9);
height: 50%;
}
Working example: http://jsfiddle.net/kboucher/FK2tL/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With