简体   繁体   中英

Having trouble increasing spacing between horizontal menu items with CSS

Here is the HTML:

<div id="menu">
    <ul>
        <li><a href="#">Home</a>
        </li>
        <li><a href="#">Blog</a>
        </li>
        <li><a href="#">About</a>
        </li>
        <li><a href="#">Contact</a>
        </li>
    </ul>
</div>

Here is the CSS:

li {
    display:inline;
    padding: 10px;
}
#menu {
    margin: 21px 646px 21px 646px;
}

I cannot seem to increase the space between the menu items. What should I adjust to do so?

try

a { 
    display: block;
    padding: 10px 30px;
}

edit

Do you want something like this ? http://jsfiddle.net/Y8Ng7/

Just remove that ridiculous margin you have for the nav and increase the li padding

li {
    display:inline;
    padding: 10px 40px;
}

To center a div element, don't do margin: 21px 646px 21px 646px;

just do margin: 21px auto;

You just need to add display:inline-block; in list menu.

Change your CSS like below :

li {
   display:inline-block;
   padding: 10px;
}

#menu {
    margin: 21px 646px 21px 646px;
}

Or See Here

Rather than trying to manipulate the list items, try adding your padding to the anchor. Ex:

#menu li a { padding: 10px; display: block; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM