Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
CSS
I am having trouble centering my navigation bar.

This is the example nav bar I am working with

<style>
/* Begin Navigation Bar Styling */
#nav {
  width: 100%;
  float: left;
  margin: 0 0 3em 0;
  padding: 0;
  list-style: none;
  background-color: #f2f2f2;
  border-bottom: 1px solid #ccc;
  border-top: 1px solid #ccc; }
#nav li {
  float: left; }
#nav li a {
  display: block;
  padding: 8px 15px;
  text-decoration: none;
  font-weight: bold;
  color: #069;
  border-right: 1px solid #ccc; }
#nav li a:hover {
  color: #c00;
  background-color: #fff; }
/* End navigation bar styling. */
</style>
but as seen, the navigation bar is not centered.

I have tried using auto margins but it doesn't work. How do I go about fixing this?
Posted
Comments
TrushnaK 31-Jul-14 2:02am    
we can't imaging your UI with just css.

I didn't see any alignment you made for center. Even after you put the alignment if it is not come, then try to put that in the div tag and align that div center.
 
Share this answer
 
Hi,


Slight change to your code,

CSS
#nav {
        width: 100%;
        float: left;
        margin: 0 0 3em 0;
        padding: 0;
        text-align:center;
        list-style: none;
        background-color: #f2f2f2;
        border-bottom: 1px solid #ccc;
        border-top: 1px solid #ccc;
    }

        #nav li {
            /*float: left;*/
            display:inline;
        }

            #nav li a {
                display: block;
                padding: 8px 15px;
                text-decoration: none;
                font-weight: bold;
                color: #069;
                border-right: 1px solid #ccc;
            }

                #nav li a:hover {
                    color: #c00;
                    background-color: #fff;
                }


Hope this is what you expected..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900