0

Hi there,
could anybody kindly tell me what the "a" (in the 1st line)is in this css and what is used for please? It is driving me insane and I can't find anything anywhere (apart from the w3c schools that says that the a is to order things alphabetiacally??)

#nav-menu li a
{
background: url(background.gif) #fff bottom left repeat-x;
height: 2em;
line-height: 2em;
float: left;
width: 9em;
display: block;
border: 0.1em solid #dcdce9;
color: #0d2474;
text-decoration: none;
text-align: center;
}

cheers

Edited by Violet_82: n/a

5
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by Violet_82
0

Have a look a this for an explanation. Start with, What is a rule or "rule set"

It's selecting an anchor element, that's inside of a list element, that's inside of an element with the id nav-menu ; and it's applying the styles between { and } to it.


Regards, Arkinder

0

Hi there,
thanks for that and I had a look at the other tutorial, good stuff. The thing is that I am pretty new to Css and HTML, so still trying to get my head around it.
So in the example below the anchor is absolutely necessary, is there any way taht I can avoid using it, as in something like

#nav-menu li
{...
1

If you remove the a then the styles listed will no longer effect that element. <!-- this is an html comment that does nothing to the code -->

<div id="nav-menu"> <!-- just #nav-menu will affect this -->
    <ul>
        <li><a href="#">Link</a></li><!-- what you currently have will affect this -->
        <li><a href="#">Link</a></li><!-- it's an anchor tag (a) in side of a list tag (li) -->
    </ul>
</div>

So removing the a from your code will cause the styles to affect the list tag, because you will only have #nav-menu li . If you just had #nav-menu it would only affect the div with the id nav-menu.


So if you have,

#nav-menu {
    background-color: blue;
}

It will make the background color of the div with the id nav-menu blue.

If you have,

#nav-menu li {
    background-color: red;
}

Any list tag inside of the div with the id nav-menu will have a red background color.


Regards, Arkinder

Edited by Arkinder: n/a

1

typical inaccurate stuff from w3schools !

have a quick look at www.w3fools.com and learn why you should treat that site's lessons with care.

What your code does is just a typical way to style your menu, which you should create as an unordered list.

Edited by drjohn: n/a

Votes + Comments
Very nice link.
0

a in the first line is for link but it would work in the following way.

#nav-menu li a{................}

This css would be applied to the link whenever it is appeared in the following order.

First there must be an element with the id "nay-menu" (#nav-menu), then after that there must be li tag and then on the following link, the above css would be applied.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.