Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 923091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:08:20+00:00 2026-05-15T19:08:20+00:00

Have a Navbar <div> , inside is a <ul> and each <li> contains a

  • 0

Have a Navbar <div>, inside is a <ul> and each <li> contains a <a> with a link (this is for a navigation bar)

I looked on Google and this site and I couldn’t find exactly what I was looking for.

What I want is to be able to keep my current style (using <li> with <a>‘s inside), and I want the <li> to be evenly distributed and centered (this part comes naturally if they are evenly distributed…) inside the <ul> (which is inside the navbar <div>).

Anyways, if that doesn’t make sense let me know, currently they are just left aligned…here’s what I have:

HTML:

<div class="navbar">
  <ul>
    <li><a href="Home">Home</a></li>
    <li><a href="Discounts">Discounts</a></li>
    <li><a href="Contact">Contact Us</a></li>
    <li><a href="About">About Us</a></li>
  </ul>
</div>

CSS:

.navbar {
    width: 100%;
    margin-left: auto ;
    margin-right: auto ;
    background-color: #ABCDEF;
}
.navbar ul {
    list-style-type: none; /*to remove bullets*/
    text-align: center;
    margin: 0px;
    padding: 0px;
    width: 90%;
    overflow: hidden;
}
.navbar li{
    float: left;
    padding: 2px;
    width: 150px;
    margin-left: auto ;
    margin-right: auto ;
}

I can also include my .navbar a{} if that is necessary.
I am very new to CSS so go easy, also I did look all over SO and Google first and couldn’t find anything quite like this (although maybe since I am new I don’t realize it’s the same).

If this is a faulty CSS method and/or there is a much easier, more commonly used way of doing this, go ahead and link/post that instead, but I would prefer this way as it makes most sense to me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:08:20+00:00Added an answer on May 15, 2026 at 7:08 pm

    This allows a widthless centered dynamic ul if you don’t want to specify 90% width:

    <!doctype html>
    <div class="navbar">
        <div id="for-ie">
            <ul>
                <li><a href="Home">Home</a></li>
                <li><a href="Discounts">Discounts</a></li>
                <li><a href="Contact">Contact Us</a></li>
                <li><a href="About">About Us</a></li>
            </ul>
        </div>
    </div>
    <style>
    .navbar {
        width: 100%;
        margin-left: auto ;
        margin-right: auto ;
        background-color: #ABCDEF;
    }
    .navbar ul {
        list-style-type: none; /*to remove bullets*/
        text-align: center;
        margin: 0 auto;
        padding: 0px;
        border:1px solid red;
        display:table;
        overflow: hidden;
    }
    .navbar li{
        float: left;
        padding: 2px;
        width: 150px;
        margin-left: auto ;
        margin-right: auto ;
    }
    </style>
    <!--[if IE]>
    <style>
        #for-ie { text-align:center; }
        #for-ie ul { display:inline-block; }
        #for-ie ul { display:inline; }
    </style>
    <![endif]-->
    

    Tested in IE6, FX 3.

    EDIT: Alternate style without the extraneous element:

    <!doctype html>
    <div class="navbar">
        <ul>
            <li><a href="Home">Home</a></li>
            <li><a href="Discounts">Discounts</a></li>
            <li><a href="Contact">Contact Us</a></li>
            <li><a href="About">About Us</a></li>
        </ul>
    </div>
    <style>
    .navbar {
        width: 100%;
        margin-left: auto ;
        margin-right: auto ;
        background-color: #ABCDEF;
    }
    .navbar ul {
        list-style-type: none; /*to remove bullets*/
        text-align: center;
        padding: 0px;
        zoom:1;
        border:1px solid red;
        overflow: hidden;
    }
    .navbar li{
        padding: 2px;
        width: 150px;
        display:inline-block;
    }
    </style>
    <!--[if IE]>
    <style>
        .navbar li { display:inline; }
    </style>
    <![endif]-->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a navigation bar like this <div id=top data-role=navbar data-type=horizontal> <ul> <li><a href=#a>A</a></li>
In this nav bar I'm working on, I have a div appear when you
I have this markup: <div class='navbar'> <div class='navbar-inner'> <div class='container'> <a class='btn btn-navbar' data-target='.nav-collapse'
I have this Twitter Bootstrap code <div class='navbar navbar-fixed-top'> <div class='navbar-inner'> <div class='container'> <a
So I have this navbar I'm making; I have a Jsfiddle to demonstrate. If
I have a nav bar with children unordered lists nested under the main navbar
If I have a chunk of code like this: .hover( function () { hoverState($(#navbar
I am using twitter bootstrap and have a fixed nav bar. The navbar has
I have the following: <div id=view> <div id=navbar> Placeholder Text </div> </div> I would
Basically, I am building a horizontal navigation bar. I have following markup: <ui:style src=../common.css

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.