CSS defines a navigation bar

Source: Internet
Author: User
The navigation bar is a commonly used module in Web pages. There are many ways to implement it. The following is how to implement it using CSS:

<Div id = "menu">
<Ul>
<Li> <a href = "#"> homepage </a> </LI>
<Li class = "menudiv"> </LI>
<Li> <a href = "#"> blog </a> </LI>
<Li class = "menudiv"> </LI>
<Li> <a href = "#"> Design </a> </LI>
<Li class = "menudiv"> </LI>
<Li> <a href = "#"> album </a> </LI>
<Li class = "menudiv"> </LI>
<Li> <a href = "#"> Forum </a> </LI>
<Li class = "menudiv"> </LI>
<Li> <a href = "#"> about </a> </LI>
</Ul>
</Div>

The CSS code is as follows:
# Menu {padding: 20px 20px 0 0}
/* Use padding: 20px 20px 0 0 to fix the menu position */
# Menu ul {float: Right; List-style: none; margin: 0px ;}
/* Added float: right so that the menu is on the right side of the page */
# Menu ul Li {float: Left; margin: 0 10px; display: block; line-Height: 28px}
/* The vertical line of the single food installation room */
. Menudiv {width: 1px; Height: 28px; Background: #999}
/* Define the style of the menu link */
# Menu ul Li A: Link, # menu ul Li A: visited {font-weight: bold; color: #666}
# Menu ul Li A: hover {}

Explanations:

<Ul> </ul> and <li> </Li> These two HTML elements are mainly used to display some information in HTML in the form of a list.

When definedId = "divid", The setting syntax for CSS is# Divid {}If it is definedClass = "divid"In CSS, the corresponding setting syntax is. divid.

# Menu ul {list-style: none; margin: 0px ;}
List-style: None. This sentence cancels the vertices before the list, because we do not need these vertices.
Margin: 0px. This statement deletes ul indent, so that all list content is not indented.

  # Menu ul Li {float: left;Margin: 0 10px; display: block; line-Height: 28px}
Here, float: Left and Right are displayed in the same row, so the floating attribute (float) is used ).
Margin: 0 10px is used to generate a 20-pixel distance between the list content (left: 10px, right: 10px)
Display: block; line-Height: 28px is used to center the text vertically.

The final effect is as follows:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.