Home >Web Front-end >HTML Tutorial >[Review the past and learn the new] Use CSS to design website navigation bar_html/css_WEB-ITnose

[Review the past and learn the new] Use CSS to design website navigation bar_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:55:271039browse

1. Preview of the navigation menu effect for background change:

  • Homepage
  • Company Channel
  • Latest News
  • Room introduction
  • Hotel service
  • Leisure and entertainment
  • Travel agency
  • Source code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>实现背景变换的导航菜单</title><!--利用#nav 定义div的样式,包括宽度、右边框、填充的符合属性、字体、字号、背景颜色和字体颜色利用#nav ul 定义 div 下的 ul 对象的样式,包括列表属性 list-style、边距 margin、填充 padding、边框 border 属性利用#nav li 定义 li 对象的样式利用#nav li a 定义 li 对象下的链接文字样式利用#nav li a:hover 定义 li 对象下的链接文字激活样式 ---><style type="text/css">#nav {    width:150px;    border-right:1px solid #000;    padding:0 0 1em 0;    margin-bottom:1em;    font-family:"宋体";    font-size:13px;    background-color:#ff9933;    color:#000000;}#nav ul {    list-style:none;    margin:0;    padding:0;    border:none;}#nav li {    margin:0;    border-bottom:1px solid #ffff00;}#nav li a {    display:block;    padding:5px 5px 5px 0.5em;    background-color:#ff9933;    color:#fff;    text-decoration:none;    width:100%;    border-right:10px solid #ffcc00;    border-left:10px solid #ffcc00;}html>body #nav li a {    width:auto;}#nav li a:hover {    background-color:#ffcc00;    color:#fff;    border-right:10px solid #ff00ff;    border-left:10px solid #ff00ff;}</style></head><body><div id="nav">  <ul>    <li><a href="#nav">首页</a></li>    <li><a href="#nav">公司频道</a></li>    <li><a href="#nav">最新动态</a></li>    <li><a href="#nav">客房介绍</a></li>    <li><a href="#nav">酒店服务</a></li>    <li><a href="#nav">休闲娱乐</a></li>    <li><a href="#nav">旅行社</a></li>  </ul></div></body></html>

    2. Use CSS to create horizontal navigation

    Effect preview:

  • Homepage
  • Company Channel
  • Latest News
  • Room Introduction
  • Hotel Services
  • Leisure and Entertainment
  • Travel Agency
  • Source code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>利用CSS制作横向导航</title><!--首先定义了ul 下li 对象,给#navh li 指定了 float:left 属性,所有的li对象都向左浮动,从而形成横向的排列形式导航的关键在于a 链接对象的样式控制,在这里使用#navh li a{} 给li 下的每一个a 链接对象编写了样式display:block 使得a 链接对象的显示方式由一段文本变为一个块状对象,这样就可以使用CSS的外边距、内边距、边框等属性给a 链接标签加上一系列样式--><style type="text/css">#navh li{ float:left;}#navh ul {    list-style:none;    margin:0;    padding:0;    border:none;}#navh li a { color:#ffffff; text-decoration:none; padding-top:4px; display:block; width:65px; height:20px; text-align:center; background-color:#6600cc; margin-left:2px; }#navh li a:hover{ background-color:#9999ff; color:#ffffff;}</style></head><body><div id="navh">  <ul>    <li><a href="#navh">首页</a></li>    <li><a href="#navh">公司频道</a></li>    <li><a href="#navh">最新动态</a></li>    <li><a href="#navh">客房介绍</a></li>    <li><a href="#navh">酒店服务</a></li>    <li><a href="#navh">休闲娱乐</a></li>    <li><a href="#navh">旅行社</a></li>  </ul></div></body></html>

    Source: Chapter 13.3 of "HTML, CSS, Javascript Web Page Production from Beginner to Master"

  • Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn