2

我使用带有下拉菜单的引导响应式导航。当站点显示在小屏幕上时,我想禁用下拉菜单并启用下拉切换按钮后面的超链接。

我已经将禁用类添加到切换按钮,但我怎样才能使它仅在 @media(max-width:480px) 时工作​​?

在这里你可以找到一个测试页面

<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>
4

3 回答 3

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);
});
于 2013-06-19T12:29:19.123 回答
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>
于 2015-11-16T13:18:14.807 回答
0
.dropdown-menu {
    border: 0 none;
    display: block;
    float: none;
    font-size: 14px;
    padding: 5px 19px;
    position: static;
    text-align: none;
}
于 2016-01-23T08:16:34.670 回答