这绝对是一道值得深思的题目,帮你明白布局的死角。css
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> * { margin: 0; padding: 0; } html, body, #app { margin: 0; padding: 0; height: 100%; } #header, #footer { height: 50px; line-height: 50px; text-align: center; background: #555; color: #fff; } #side { width: 200px; background: #eee; } /*css here*/ </style> </head> <body> <div id="app"> <header id="header">header</header> <aside id="side">side</aside> <div id="main"> <ul> <li><a href="https://www.bilibili.com/1">Link1</a></li> <li><a href="https://www.bilibili.com/1">Link2</a></li> <li><a href="https://www.bilibili.com/1">Link3</a></li> <br> <li><a href="https://www.bilibili.com/1">Link4</a></li> <li><a href="https://www.bilibili.com/1">Link5</a></li> </ul> </div> <footer id="footer">footer</footer> </div> <script> // JS here </script> </body> </html>
一、完成经典的上 header ,下 footer ,左边是侧边栏,右边是内容。
二、去掉列表前面的 · ,列表项水平排列,注意里面的br标签须要换行,同时每两个li后有一条竖线。
三、点击列表项不跳转,弹出href内的内容。html
/* css here */ #side{ float: left; height: calc(100% - 100px); } #main{ margin-left: 200px; height: calc(100% - 100px); }
个人解决方式,是解决了问题,但是都不算完美app
#app{ position: relative; } #side{ position: absolute; left: 0; top: 50px; height: calc(100% - 100px); } #main{ margin-left: 200px; height: calc(100% - 100px); }
更完美的的方式(或许不能称更完美,只是想到了一些平时布局不会去用的方式,而它却比较使用)ide
/* css here */ #app{ position: relative; } #side{ position: absolute; left: 0; top: 50px; bottom: 50px; } #main{ position: absolute; left: 200px; top: 50px; right: 0; bottom: 50px; } #footer { /* footer 设置 绝对定位 */ position: absolute; bottom: 0; width: 100%; /* 设置浮动后,补上宽度 */ }
/*css here*/ #app{ display: flex; flex-wrap: wrap; } #header, #footer { width: 100%; } #side{ height: calc(100% - 100px); } #main{ height: calc(100% - 100px); flex: 1; }
暂无布局
#main li{ list-style: none; float: left; } #main li:nth-of-type(2n){ border-right: 1px solid #000; }
document.querySelectorAll('ul')[0].addEventListener('click',event => { if(event.target.tagName === 'A') { event.preventDefault(); // 阻止默认行为 alert(event.target.getAttribute('href')); } });