There are many different ways to achieve this, here are a few of them.
1. using float + overflow :
Please note that there should not be any float in the content field, and overflow:auto may prevent wrapped text from going under the sidebar.
.container:after { content: ""; display: table; clear: both; } .sidebar { background: pink; width: 150px; float: left; } .content { background: gold; overflow: auto; }
<div class="container"> <div class="sidebar">sidebar</div> <div class="content">content</div> </div>
2: using float + calc :
See browser support tables - mostly IE9 +.
.container:after { content: ""; display: table; clear: both; } .sidebar { background: pink; width: 150px; float: left; } .content { background: gold; width: calc(100% - 150px); float: left; }
<div class="container"> <div class="sidebar">sidebar</div> <div class="content">content</div> </div>
3. using display:inline-block + calc :
.container { font-size: 0; } .sidebar, .content { font-size: 16px; display: inline-block; } .sidebar { background: pink; width: 150px; } .content { background: gold; width: calc(100% - 150px); }
<div class="container"> <div class="sidebar">sidebar</div> <div class="content">content</div> </div>
4. using the CSS table:
.container { display: table; width: 100%; } .sidebar, .content { display: table-cell; } .sidebar { background: pink; width: 150px; } .content { background: gold; }
<div class="container"> <div class="sidebar">sidebar</div> <div class="content">content</div> </div>
5. using flexbox:
See browser support tables - IE10 + with prefixes .
.container { display: flex; } .sidebar { background: pink; flex: 0 0 150px; } .content { background: gold; flex: 1; }
<div class="container"> <div class="sidebar">sidebar</div> <div class="content">content</div> </div>
source share