<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .layui-side{ position:fixed; width:200px; top:0; bottom:0; background-color: #393D49; } </style> </head> <body> <div class="layui-side layui-bg-black"> </div> </body>
這樣寫還有一個好處就是,側邊欄的高度是不固定的,它可以隨不同大小的瀏覽器窗口而變化,兼容性也非常好IE8也行
(2)css固定頂部導航簡單的寫法:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> html,body{ margin:0; padding:0 } .header{ height:80px; width:100%; background-color:#ccc; } .fix-header{ position:fixed; top:0 } .content{ height:1000px; padding-top:80px; background-color: #5fb878; } </style> </head> <body> <div class="header fix-header">固定的頂部導航條</div> <div class="content">23333</div> </body> </html>