<div class="container elem"> <span class="label begin"> <div class="container"> </span> <nav class="elem elem-red"> <span class="label begin"> <nav></span> <ul> <li>nav-item1</li> <li>nav-item2</li> <li>nav-item3</li> <li>nav-item4</li> <li>nav-item5</li> <li>nav-item6</li> </ul> <span class="label end"> </nav> </span> </nav> <section class="elem elem-orange"> <span class="label begin"> <section></span> <p>section的 margin-left 样式确保了有足够的空间容纳 nav 元素。</p> <span class="label end"> </section> </span> </section> <section class="elem elem-orange"> <span class="label begin"> <section></span> <p>一些内容</p> <span class="label end"> </section> </span> </section> <section class="elem elem-orange"> <span class="label begin"> <section></span> <p>注意当你调整浏览器窗口时发生了什么。效果很赞!</p> <span class="label end"> </section> </span> </section> </div> <footer class="elem elem-green"> <span class="label begin"> <footer> </span> <p>如果你使用了一个固定定位的页眉或页脚,确保有足够的空间来显示它们!我在 body 上面加了 margin-bottom 。</p> <span class="label end"> </footer> </span> </footer>
* { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .elem{ border:solid #6AC5AC 3px; position:relative; } .elem-red { border: solid #D64078 3px; } .elem-orange { border: solid #FDC72F 3px; } .elem-green { border: solid #96C02E 3px; } .label{ position:absolute; background-color:#6AC5AC; line-height:1em; padding:3px; } .elem-red > .label{ background-color:#D64078; } .elem-orange > .label{ background-color:#FDC72F; } .begin{ left:0; top:0; } .end{ right:0; bottom:0; } p{ margin:2em 0; display:block; } .container { position: relative; } nav,nav.elem { position: absolute; left: 0px; width: 200px; } section { /* position is static by default */ margin-left: 200px; } footer,footer.elem { position: fixed; bottom: 0; left: 0; height: 70px; background-color: white; width: 100%; } body { margin-bottom: 120px; }