Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a bigger space between menu items (nav)

Tags:

html

css

I started creating my first web-page with HTML5 and some CSS styles in it. I have faced a problem i was hoping some could clear out for me.

I'm trying to make space between my menu items like:

ABOUT        HELP       CONTACT

I have found a simple method in how to do that, but it does not do the job good enough. As an example i have 2 menus created out of an nav element like this:

<nav class="nav2">      
    <li><a href="Højtalere.html">Stereo</a></li>
    <li><a href="Forstærkere.html">Højtalere</a></li>
    <li><a href="åbningstider.html">TV og hjemmebiograf</a></li>
    <li><a href="Computer.html">Streaming</a></li>
    <li><a href="Tilbehør.html">Tilbehør</a></li>
    <li><a href="Kabler.html">Kabler</a></li>       
</nav>  

<nav class="nav3">          
    <li><a href="login.html" style="display: inline;">Text</a></li>
    <li><a href="support.html" style="display: inline;">Text</a></li>
    <li><a href="???.html" style="display: inline;">Text</a></li>           
</nav>

Right now i have made the space with this css code:

li {
   display: inline;
   margin-right: 20px;
   }

The problem is that it makes the same space for all the li elements, how do i code it so i can control lets say the nav2 should have margin-right: 10px, but the other should have 40px in space between?

Hope you guys understand what i'm trying to do

like image 200
Mikkel Avatar asked Jan 06 '15 15:01

Mikkel


People also ask

How do you separate NAV items?

I would suggest you give each nav element different classes (or Id's) so you can then target each one separately in your CSS and apply your desired styling. For example you can give the horizontal nav a class="horizontal-nav" and the vertical nav a class="vertical-nav".

How can I make my nav bar full width?

The simplest way to get the effect you are looking for (for any number of buttons) is to use a table with a 100% width. A more complicated way is to give each button an equal percentage width such that with the number of buttons it adds up to 100%. You have 5 buttons, so you can put width:20%; on #nav ul li .

How do you add space between elements in HTML?

You can add space in HTML to any lines of text. You can use the &nbsp; HTML entity to create blank spaces in both paragraph text and text in tables, for example. Since there is no blank space keyboard character in HTML, you must type the entity &nbsp; for each space to add.


2 Answers

simply:

li {
    margin-right: 40px;
}
.nav2 li {
    margin-right: 10px;
}
like image 156
Super Babaca Avatar answered Oct 11 '22 15:10

Super Babaca


You can use the following:

.nav2 li {
    margin-right: 20px;
}
li {
    display: inline;
    margin-right: 40px;
}

Like this you set different rule to li elements that has ancestor with class .nav2.

like image 20
Alex Char Avatar answered Oct 11 '22 15:10

Alex Char