Jump to content
Sign in to follow this  
ke2211975

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>
<html>
<head>
<title></title>
<style>

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

li{
float: left;
}

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

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

</style>
</head>

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

<ul>
<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>
</ul>

</body>
</html>

 

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.

Guest
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.

Loading...
Sign in to follow this  

×
×
  • Create New...