如題,持續總結自己在使用BootStrap中遇到的問題,並記錄解決方法。希望能幫到需要的朋友
應用場景:經典上下佈局中,頂部導航條固定,下部填充不顯示捲軸
解決方案:導航條固定在頂部,同時為body設定內邊距(padding-top),內邊距為導航條高度(預設50px,可自行調整高度),html程式碼如下:
<!--html页面布局--> <div class="container-fluid page-wrapper"> <!--导航栏--> <div class="navbar navbar-default navbar-fixed-top" role="navigation"> <div class="container"> <!--logo图标--> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myMenu"> <span class="sr-only">切换导航条</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href=""> <img src="images/logo_2.png" alt=""> </a> </div> <!--导航栏菜单--> <div class="collapse navbar-collapse" id="myMenu"> <ul class="nav navbar-nav"> <li> <a href="index.html" >主页</a> </li> <li> <a href="#" data-toggle="modal">河道站点</a> </li> <li> <a href="#" data-toggle="modal">水库站点</a> </li> <li> <a href="#">气象站点</a> </li> <li> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">降雨量<span class="caret"></span> </a> <ul class="dropdown-menu"> <li> <a data-toggle="modal">1小时降雨</a> </li> <li> <a href="#">3小时降雨</a> </li> <li> <a href="#">24小时降雨</a> </li> </ul> </li> </ul> <form class="navbar-form navbar-left" role="search"> <div class="form-group"> <input type="text" id="datetimepicker" class="form-control" placeholder="选择日期"> </div> <button type="button" class="btn btn-default">确定</button> </form> </div> </div> </div> <!--地图窗口--> <div class="container-fluid" id="map"></div> </div> </body> </html>
CSS代碼:
*{ margin:0; padding:0; border:0; } html, body{ height:100%; width:100%; overflow:hidden; } body{ padding-top:50px; } .page-wrapper{ margin:0; padding:0; height:100%; overflow:hidden; } #map{ width:100%; height:100%; }
實現效果:
希望本文所述對大家學習Bootstrap有幫助。