Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 496
codacopia Avatar asked May 06 '14 23:05

codacopia


People also ask

How do I add a space between horizontal list in CSS?

To create space between list bullets and text in HTML, use CSS padding property. Left padding padding-left is to be added to <ul> tag list item i.e. <li> tag. Through this, padding gets added, which will create space between list bullets and text in HTML.

How do you put space between menu items in CSS?

The best way to add space between two HTML elements is to add either padding or a margin in CSS. padding will add space to the outside of an element and margins will add space between two elements.

Which CSS property controls the spacing between elements?

The CSS margin property controls the space between different HTML elements on a webpage. Use margin to bring page elements closer together or to move them further apart.


2 Answers

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;

like image 154
CRABOLO Avatar answered Sep 28 '22 12:09

CRABOLO


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

like image 45
Ajay Gupta Avatar answered Sep 28 '22 10:09

Ajay Gupta