簡單的兩個固定寬度列布局
簡單的兩列布局由兩個固定寬度的浮動元素組成。請注意,在此示例中,側邊欄和內容區域的高度不同。這是使用浮點數的多列布局的棘手部分之一,並且需要使用變通方法來使多個列看起來具有相同的高度。
HTML:
<div class="wrapper">
<div class="sidebar">
<h2>Sidebar</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio.</p>
</div>
<div class="content">
<h1>Content</h1>
<p>Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. </p>
</div>
</div>
CSS:
.wrapper {
width:600px;
padding:20px;
background-color:pink;
/* Floated elements don't use any height. Adding "overflow:hidden;" forces the
parent element to expand to contain its floated children. */
overflow:hidden;
}
.sidebar {
width:150px;
float:left;
background-color:blue;
}
.content {
width:450px;
float:right;
background-color:yellow;
}