用css制作动态水平按钮菜单
2008-07-28 17:23
501 查看
CSS 菜单 - 水平 - 简单的按钮
这篇文章将知道用XHTML 和 CSS 常见一个简单的水平按钮菜单. 下面是最终效果:
.MainMenu ul {height: 28px;
list-style: none;
margin: 0 auto;
padding: 0;
width: 280px;
}
.MainMenu ul li {
list-style: none;
background: #FFF;
border: 1px solid #999;
float: left;
}
.MainMenu ul li a {
background: #DDD;
border: 0;
color: #000;
display: block;
font-size: 11px;
height: 24px;
line-height: 24px;
margin: 1px;
outline: none;
text-align: center;
width: 90px;
}
.MainMenu ul li#Button2,.MainMenu li#Button3 {
border-left: 0;
}
.MainMenu ul li a:hover {
background: #222;
color: #CC9900;
}
Button 1
Button 2
Button 3
1.记住在所有的利用 CSS/XHTML设计的代码中我们都要尽量保持代码的最少化.首先让我们建立我们需要的最基本的html代码, 注意,这里要符合Web 2.0 的标准,所有的菜单创建都要用<ul>标签:
Code: <ul id="Menu"> <li><a href="">Button 1</a></li> <li><a href="">Button 2</a></li> <li><a href="">Button 3</a></li> </ul> | Preview: Button 1 Button 2 Button 3 |
Code: <style> #Menu { list-style: none; margin: 0; padding: 0; } </style> <ul id="Menu"> <li><a href="">Button 1</a></li> <li><a href="">Button 2</a></li> <li><a href="">Button 3</a></li> </ul> | Preview: #Menu02 ul li { list-style: none; margin: 0; padding: 0; } Button 1 Button 2 Button 3 |
Code: <style> #Menu { list-style: none; margin: 0; padding: 0; } #Menu li{ float: left; } </style> <ul id="Menu"> <li><a href="">Button 1</a></li> <li><a href="">Button 2</a></li> <li><a href="">Button 3</a></li> </ul> | Preview: #Menu03 ul { list-style: none; margin: 0; padding: 0; } #Menu03 ul li { list-style: none; float: left; } Button 1 Button 2 Button 3 |
buttons we need to set it's display property to block.
This will allow us to regulate its width and height. After which we can
give it some styling. Note that the href property in the link must be
set for this to work.
Code: <style> #Menu { list-style: none; margin: 0; padding: 0; } #Menu li{ float: left; } #Menu li a { background: #DDD; border: 0; color: #000; display: block; font-size: 11px; height: 24px; width: 90px; } </style> <ul id="Menu"> <li><a href="">Button 1</a></li> <li><a href="">Button 2</a></li> <li><a href="">Button 3</a></li> </ul> | Preview: #Menu04 ul { list-style: none; margin: 0; padding: 0; } #Menu04 ul li { list-style: none; float: left; } #Menu04 ul li a { background: #DDD; border: 0; color: #000; display: block; font-size: 11px; height: 24px; width: 90px; } Button 1 Button 2 Button 3 |
line-height style, and horizontally using the text-align
style.
Code: <style> #Menu { list-style: none; margin: 0; padding: 0; } #Menu li{ float: left; } #Menu li a { background: #DDD; border: 0; color: #000; display: block; font-size: 11px; height: 24px; line-height: 24px; text-align: center; width: 90px; } </style> <ul id="Menu"> <li><a href="">Button 1</a></li> <li><a href="">Button 2</a></li> <li><a href="">Button 3</a></li> </ul> | Preview: #Menu05 ul { list-style: none; margin: 0; padding: 0; } #Menu05 ul li { list-style: none; float: left; } #Menu05 ul li a { background: #DDD; border: 0; color: #000; display: block; font-size: 11px; height: 24px; line-height: 24px; text-align: center; width: 90px; } Button 1 Button 2 Button 3 |
on the button by giving the list elements a border and a background
color and then setting a 1px margin on the buttons.
Code: <style> #Menu { list-style: none; margin: 0; padding: 0; } #Menu li{ background: #FFF; border: 1px solid #999; float: left; } #Menu li a { background: #DDD; border: 0; color: #000; display: block; font-size: 11px; height: 24px; line-height: 24px; margin: 1px; text-align: center; width: 90px; } </style> <ul id="Menu"> <li><a href="">Button 1</a></li> <li><a href="">Button 2</a></li> <li><a href="">Button 3</a></li> </ul> |
Preview: #Menu06 ul { list-style: none; margin: 0; padding: 0; } #Menu06 ul li { list-style: none; background: #FFF; border: 1px solid #999; float: left; } #Menu06 ul li a { background: #DDD; border: 0; color: #000; display: block; font-size: 11px; height: 24px; line-height: 24px; margin: 1px; text-align: center; width: 90px; } Button 1 Button 2 Button 3 |
the button to change the way they look when you move your mouse over
them.
Code: <style> #Menu { list-style: none; margin: 0; padding: 0; } #Menu li{ background: #FFF; border: 1px solid #999; float: left; } #Menu li a { background: #DDD; border: 0; color: #000; display: block; font-size: 11px; height: 24px; line-height: 24px; margin: 1px; text-align: center; width: 90px; } #Menu li a:hover { background: #222; color: #CC9900; } </style> <ul id="Menu"> <li><a href="">Button 1</a></li> <li><a href="">Button 2</a></li> <li><a href="">Button 3</a></li> </ul> |
Preview: #Menu07 ul { list-style: none; margin: 0; padding: 0; } #Menu07 ul li { list-style: none; background: #FFF; border: 1px solid #999; float: left; } #Menu07 ul li a { background: #DDD; border: 0; color: #000; display: block; font-size: 11px; height: 24px; line-height: 24px; margin: 1px; text-align: center; width: 90px; } #Menu07 ul li a:hover { background: #222; color: #CC9900; } Button 1 Button 2 Button 3 |
the buttons in the middle, we will need to give all buttons an id and
then remove the borders per id.
Code: <style> #Menu { list-style: none; margin: 0; padding: 0; } #Menu li{ background: #FFF; border: 1px solid #999; float: left; } #Menu li a { background: #DDD; border: 0; color: #000; display: block; font-size: 11px; height: 24px; line-height: 24px; margin: 1px; text-align: center; width: 90px; } #Menu li a:hover { background: #222; color: #CC9900; } #Menu li#Button2, #Menu li#Button3 { border-left: 0; } </style> <ul id="Menu"> <li id="Button1"><a href="">Button 1</a></li> <li id="Button2"><a href="">Button 2</a></li> <li id="Button3"><a href="">Button 3</a></li> </ul> |
Preview: #Menu08 li { list-style: none; background: #FFF; border: 1px solid #999; float: left; } #Menu08 li a { background: #DDD; border: 0; color: #000; display: block; font-size: 11px; height: 24px; line-height: 24px; margin: 1px; text-align: center; width: 90px; } #Menu08 li a:hover { background: #222; color: #CC9900; } #Menu08 li#Button2,#Menu08 li#Button3 { border-left: 0; } Button 1 Button 2 Button 3 |
Button 1
Button 2
Button 3
原帖地址:http://www.globexdesigns.com/resources/css/menu01.php
相关文章推荐
- 使用css+js制作水平菜单
- DIV+CSS制作的水平三级横向弹出菜单
- CSS制作水平导航菜单效果
- div+css制作的水平三级横向弹出菜单
- CSS实现水平菜单制作
- html+ js+ jq+css导航条菜单的制作(水平,竖直,伸缩,带有动画效果等等。。。)
- HTML/CSS导航菜单-水平菜单的制作
- 可刷新的DivCSSJS制作的树型菜单
- jsp将菜单include 进页面后,js动态改变当前菜单链接CSS
- 解读M$源代码:JavaScript+CSS实现动态菜单显示
- 下拉水平菜单 js div+css 超实用 可链接数据库
- 利用滑动门原理制作圆角和渐变色按钮【css】
- 利用CSS、JQuery和div实现动态多级菜单
- JavaScript+Css实现的鼠标悬停时动态翻滚的紫色菜单导航
- 如何用CSS制作横向菜单?
- 纯CSS制作三级菜单,可扩展无限
- DIV+CSS制作二级横向弹出菜单,略简单
- JavaScript实现动态下拉收起菜单+css实现动画效果
- CSS制作三角形和按钮
- 创建水平菜单CSS