我使用带有下拉列表的bootstrap响应式导航。当网站显示在小屏幕上时,我想禁用下拉菜单并启用下拉切换按钮后面的超链接。
我已将禁用的类添加到切换按钮但是如何才能使它仅在@media(max-width:480px)时工作?
您可以在这里找到test page
<div class="row nav_row mobile">
<ul class="nav nav-pills dropdown nav_responsive">
<li><a class="dropdown-toggle collapse-btn">Menu<span class="caret"></span></a></li>
</ul>
<div class="nav-collapse">
<ul class="nav nav-pills">
<li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#">Vakanties <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Binnenland</a></li>
<li><a href="#">Buitenland</a></li>
<li><a href="#">Inleefreizen</a></li>
<li><a href="#">Gezondheidsreizen</a></li>
</ul>
</li>
<li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#">Vormingen <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Monitor</a></li>
<li><a href="#">Hoofdmonitor</a></li>
<li><a href="#">Instructeur</a></li>
</ul>
</li>
<li><a href="#">Gezondheid</a></li>
<li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#">Internationaal <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">EVS</a></li>
<li><a href="#">Groepsuitwisselingen</a></li>
<li><a href="#">Trainingscursussen</a></li>
</ul>
</li>
<li><a href="#">Projecten</a></li>
<li class="clearfix"><a href="#">Actueel</a></li>
</ul>
<div style="clear:left"></div>
</div>
</div>
答案 0 :(得分:3)
我找到了一个可以接受的答案。有点Jquery帮助
$(document).ready(function() {
function checkWidth() {
var windowSize = $(window).width();
if (windowSize > 480) {
$('.disabled').removeClass('disabled').addClass('enabled');
} else if (windowSize <= 479) {
$('.enabled').removeClass('enabled').addClass('disabled');
}
}
// Execute on load
checkWidth();
// Bind event listener
$(window).resize(checkWidth);
});
答案 1 :(得分:1)
我使用Bootstrap Responsive Utilities修复了类似的问题,以显示和隐藏选定的div。所以基本上我创建了两个菜单 - 一个仅在XS屏幕上可见,另一个在所有其他屏幕尺寸中都可见。
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#mycollapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<div class="hidden-xs">
<ul class="nav navbar-nav navbar-right">
<!-- NAVBAR ITEMS FOR LARGER THAN XS SCREENS -->
</ul>
</div>
<div class="visible-xs hidden-sm hidden-md hidden-lg">
<div class="collapse navbar-collapse" id="mycollapse">
<ul class="nav navbar-nav navbar-right">
<!-- NAVBAR ITEMS FOR XS SCREEN -->
</ul>
</div>
</div>
</nav>
</div>
</div>
</div>
答案 2 :(得分:0)
.dropdown-menu {
border: 0 none;
display: block;
float: none;
font-size: 14px;
padding: 5px 19px;
position: static;
text-align: none;
}