Jump to content
Sign in to follow this  

About styling a list horizontally to create a navigation menu

Recommended Posts

Below is the way showed on W3 tutorial, I curious what the difference to put CSS property: float in "li a" style but "li"? Why?

<!DOCTYPE html>

list-style-type: none;
padding: 0px;
margin: 0px;
overflow: hidden;
background-color: #333333

float: left;

li a{
display: block;
color: #ffffff;
text-decoration: none;
text-align: center;
float: block;

li a:hover{
background-color: #111111;


<h1>nvigation menu</h1>
<p>Use CCS to style the list horizonally, to create navigation menu</p>

<li><a href="deafalt.asp"  target="_self" >Home</a></li>
<li><a href="deafalt.asp"  target="_self">News</a></li>
<li><a href="deafalt.asp"  target="_self" >Contact</a></li>
<li><a href="deafalt.asp"  target="_self" >About</a></li>



Share this post

Link to post
Share on other sites

<li> elements are block level tags, which means they usually take up the full page width, forcing the next li element to go on the next line.

By floating them, we can take them out of normal page flow, and put them next to each other.


Putting the float in li means that we float the li. This is the reason why its horizontal.

Styling li a is actually styling the links and not the container. The container (li) normally goes vertically

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...