按住导航栏品牌左侧的按钮

时间:2015-05-15 05:49:03

标签: javascript jquery html css twitter-bootstrap

我想在navbar-brand的左侧放一个按钮来切换侧边栏。按钮切换侧边栏。在桌面模式下,它可以正常工作,但在较小的屏幕上,它会改变位置并进入导航栏品牌的右侧。 以下是截图。

enter image description here

enter image description here

    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <button type="button" data-toggle="#sidebar" id="sidebar-toggle" class="navbar-left navbar-toggle">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="Login.aspx" style="vertical-align: middle">
                    <img src="Logo.png" style="vertical-align: middle" /></a>
                <label class="navbar-text text-center text-primary" style="vertical-align:10px;font-size:medium">Example Distribution</label>
            </div>
            <div class="navbar-collapse collapse" id="navbar">
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="#">Dashboard</a></li>
                    <li><a href="#">Settings</a></li>
                    <li><a href="#">Profile</a></li>
                    <li><a href="#">Help</a></li>
                </ul>
                <form class="navbar-form navbar-right">
                    <input type="text" class="form-control" placeholder="Search..." />
                </form>
            </div>
        </div>
    </nav>
    <div class="container-sidebar">
        <div id="sidebar">
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">Explore</a></li>
                <li><a href="#">Users</a></li>
                <li><a href="#">Sign Out</a></li>
            </ul>
        </div>
    </div>

2 个答案:

答案 0 :(得分:3)

只需添加此css课程pull-left DEMO

  <button type="button" data-toggle="#sidebar" id="sidebar-toggle" class=" navbar-toggle pull-left">

答案 1 :(得分:2)

只需在document.ready

上添加此代码即可

可能有CSS选择,但我觉得这很容易!

<强> DEMO

$(document).ready(function(){
    if($(window).width()<768)
    {
        $('#sidebar-toggle').css('float','left');
    }
    $(window).on('resize',function(){
        if($(window).width()<768)
        {
            console.log('here');
              $('#sidebar-toggle').css('float','left');
        }
    });
});

CSS解决方案:

@media screen and (max-width: 768px) {
     #sidebar-toggle{
        float:left !important;
     }
}

更新了 DEMO