It’s time to introduce you to a valid and strict menu, á la XHTML style!
Since there are people with certain disabilities we want to make their stay a little bit easier. There are special programs that, for example, reads out correct menues to the user with a “computer voice”. This is very useful to peoples that has problems with reading, either by a decease, vision disabilities or reading or writing difficulties.
A correct menu should be built with <ul> and <li>. Here’s an example:
<ul>
<li><a href=”link.php”>My link</a></li>
<li><a href=”link.php”>My link</a></li>
<li><a href=”link.php”>My link</a></li>
</ul>
<ul> and <li> are mainly used to make lists, but since it’s possible to do some heavy modifications using CSS, we have a great way to make a menu right here.
That code above would without CSS look a bit silly. Here’s how it would be on a homepage without CSS:
I always like to put my menues inside a div, to make it easier to edit them with CSS. Therefor, I would recommend wrapping the <ul> and </ul> up with a div, and let’s call it “menu_div”.
This would look like this:
<div id=”menu_div”>
<ul>
<li><a href=”link.php”>My link</a></li>
<li><a href=”link.php”>My link</a></li>
<li><a href=”link.php”>My link</a></li>
</ul>
</div>
I don’t want the little dots to be there, so I make a little modification with CSS. I would also want them to be displayed inline instead.
#menu_div ul {
list-style-type: none;
display: inline;
}
Notice that I put “ul” right after the name of the div. This is to show the browser that it’s everything inside of “ul” that we want to edit, not the whole menu_div.
List-style-type tells the browser that there should be no dots or whatever on our list.
Display tells the browser how the list should be displayed. In this case: inline.
An attribute that I haven’t introduced to you before is margin. This little sweety allows us to move the menu x pixels up, right, down or left. I would like my inline menu to make a space between each link. This can’t be done inside of <ul>, since it contain’s the <li> which has my links. So, let’s make the margins inside of <li>, like this:
#menu_div li {
margin: 4px 2px 1px 0;
}
The numbers above are a bit strange, right? I just typed those random numbers in to be able to do this example. So, why are there 4 different numbers, and why does one of them not have “px”?
As I wrote previously, margin let’s us change the space between top, right, left or down - and this is what the numbers are for. 4px is the space to the top, 2px to the right, 1px to the bottom and 0 to the left. 0 does not have to be defined as px (pixels), since it’s zero!
And without my crappy english:
margin: top right bottom left;
And remember to define the numbers as px!
We will be continuing to modify this menu in the next step! Please feel free to leave a comment if you have any thoughts about this post!