简体   繁体   中英

How can set navbar width full for mobile-screen(less than 600px) in bootstrap?

In image(given below) navbar is not taking full width.I want it will take full width in small screen(<600px).Relative code and screenshot are given below.I tried in many ways but failed.

HTML:

<header class="header-area">
            <nav class="header-nav navbar">
                <div class="container-fluid">
                    <ul class="nav navbar-nav text-center text-uppercase">
                        <li><a href="#">About us</a></li>
                        <li><a href="#">Work</a></li>
                        <li>
                            <a href="#">
                                <img src="images/logo1.png" class="img-responsive" alt="website-logo" style="width: 80px;height:auto;"/>
                            </a>
                        </li>
                        <li><a href="#">Shop</a></li>
                        <li><a href="#">Contact</a></li>
                    </ul>
                </div>
            </nav>
        </header>

CSS:

header-area {
    background: url("images/background1.jpg") no-repeat 0 0 / 100% 100%;
    color: #84828D;
    padding-bottom: 474px;
}
.header-nav .nav, .header-nav .nav.navbar-nav {
    width: 100%;
    float: inherit;
}
.header-nav.navbar .nav, .navbar .nav > li {
    float: inherit;
    display: inline-block;
    vertical-align: middle;
}

MEDIA-QUERY:

@media all and (max-width: 600px) {
    .navbar .nav > li {
        display: block;
    }
    .navbar .nav > li  img {
        margin: auto;
    }
}

问题

Well add some line to your media query like this

@media all and (max-width: 600px) {
    .container-fluid {
        padding:0; /* Extend your menu really full width without padding of container-fluid */
    }
    .navbar-nav {
        margin:0; /* Center your menu with current 100% width available */
    }
    .navbar .nav > li {
        display: block;
    }
    .navbar .nav > li  img {
        margin: auto;
    }
}

Hope this help!

Reason following CSS in bootstrap.css causing the menu pushing -15px inside

.navbar-nav {
    margin: 7.5px -15px;
}

Add following CSS in your media query with 0px so menu expand to full width of container

.navbar-nav {
    margin: 7.5px 0px;
}

To

@media all and (max-width: 600px) {
    .navbar-nav {
        margin: 7.5px 0px;
    }   
    .navbar .nav > li {
        display: block;
    }
    .navbar .nav > li  img {
        margin: auto;
    }
}

Fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM