Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. I've created a horizontal menu. However, due to the fact that two of the links in the menu have long names (and are just next to each other), they appear to be messy. I'd like all of the links to have the same spacing between them. Like the menu at:
http://www.w3schools.com/cssref/css3_pr_box-shadow.asp[^]

My code:
HTML
HTML
<!doctype html>
<html>
    <head>
        <title>Nothing yet</title>
        <meta charset="utf-8">
        <link rel="stylesheet" href="reset.css">
        <link rel="stylesheet" href="base2.css">                  
    </head>
    
    	<body>
    		 <nav>
                 <ul>
                    <li><a href="#">HOME</a></li> 
                    <li><a href="#">ABOUT</a></li>
                    <li><a href="#">LEARNING</a></li>
                    <li><a href="#">PROJECTS</a></li>    
                    <li><a href="#">WORK</a></li>
                    <li><a href="#">CONTACT</a></li>    
                </ul>     
            </nav>
        </body>
</html>

CSS
CSS
@charset "utf-8";
/* CSS Document */

body {
    font-family: segoe ui, helvetica, lato, sans-serif;	
    background-color: #E9E9E9;
}

p {
    font-size: 2em;
    color: black;
}

nav {
    background-color: #008cff;
    height: 50px;
    position: fixed; /* This and the 'left', 'top' and 'width' fixes the menu */
    left: 0;
    top: 0;
    width: 100%;
    box-shadow: 0px 2px 5px #949494; 
}

nav ul {
    height: 50;
    width: 660px;
    margin: auto;
}

nav ul li {
    list-style-type: none;
    width: 110px; 
    float: left;
    text-align: center;
    font-size: 1.2em;	
}

nav a {
    text-decoration: none;
    color: #ECECEC;
    line-height: 50px; 
    display: block;	
}

nav a:hover {
    color: white;
    background-color: #007CE3;	
}
Posted
Updated 19-Nov-15 8:14am
v2

change in your CSS

HTML
nav ul li {
   width: auto;
   margin-right: 25px;
}

(leave the rest of that block the same!)
 
Share this answer
 
v2
This would do-
CSS
nav ul li {
    list-style-type: none;
    width: 16.666666667%; /* (100 / numofItems)% */
    float: left;
    text-align: center;
    font-size: 1.2em;	
}


-KR
 
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