Home > Web Front-end > CSS Tutorial > How to Center Navigation Links in Twitter Bootstrap Navbar?

How to Center Navigation Links in Twitter Bootstrap Navbar?

DDD
Release: 2024-11-01 09:26:02
Original
1102 people have browsed it

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:

<code class="css">.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;
}</code>
Copy after login

Alternative Approach

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

<code class="html"><div class="navbar navbar-fixed-top center">
    <div class="navbar-inner">
        ....
    </div>
</div></code>
Copy after login

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

<code class="css">.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;
}</code>
Copy after login

Additional Considerations

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

<code class="css">.center .dropdown-menu {
    text-align: left;
}</code>
Copy after login

The above is the detailed content of How to Center Navigation Links in Twitter Bootstrap Navbar?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template