"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Center Navigation Links in Twitter Bootstrap Navbar?

How to Center Navigation Links in Twitter Bootstrap Navbar?

Published on 2024-11-11
Browse:341

How to Center Navigation Links in Twitter Bootstrap Navbar?

Modifying Twitter Bootstrap Navbar to Center Links

When working with the Twitter Bootstrap navbar, users may encounter the need to align navigation links centrally, rather than the default left alignment. To achieve this, make the following customizations using the CSS stylesheet.

Solution

To center the navigation links in the navbar, implement the following CSS code:

.navbar .nav,
.navbar .nav > li {
    float: none;
    display: inline-block;
    *display: inline; /* ie7 fix */
    *zoom: 1; /* hasLayout ie7 trigger */
    vertical-align: top;
}

.navbar-inner {
    text-align: center;
}

Alternative Approach

To preserve the Bootstrap defaults and target a specific navbar menu, create a custom class and apply it to the navbar container:

Then, target the .center class in the CSS stylesheet:

.center.navbar .nav,
.center.navbar .nav > li {
    float: none;
    display: inline-block;
    *display: inline; /* ie7 fix */
    *zoom: 1; /* hasLayout ie7 trigger */
    vertical-align: top;
}

.center .navbar-inner {
    text-align: center;
}

Additional Considerations

To align submenu items to the left, add the following CSS rule:

.center .dropdown-menu {
    text-align: left;
}
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3