這篇文章主要為大家詳細介紹了BootStrap實用代碼片段之一,總結(jié)在使用BootStrap中遇到的問題,并記錄解決方法,感興趣的小伙伴們可以參考一下
應(yīng)用場景:經(jīng)典上下布局中,頂部導(dǎo)航條固定,下部填充不顯示滾動條
解決方案:導(dǎo)航條固定在頂部,同時為body設(shè)置內(nèi)邊距(padding-top),內(nèi)邊距為導(dǎo)航條高度(默認(rèn)50px,可自己調(diào)整高度),html代碼如下:
<!--html頁面布局-->
<div class="container-fluid page-wrapper">
<!--導(dǎo)航欄-->
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<!--logo圖標(biāo)-->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myMenu">
<span class="sr-only">切換導(dǎo)航條</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>
<!--導(dǎo)航欄菜單-->
<div class="collapse navbar-collapse" id="myMenu">
<ul class="nav navbar-nav">
<li>
<a href="index.html" style="">主頁</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%;
}
希望本文所述對大家學(xué)習(xí)Bootstrap有所幫助。