当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > 用 CSS 让你的按钮(button)更加迷人

CSS样式表
CSS Sprites 技术分析
csdn 博客的 css样式 v5
CSS 实例实现清除浮动
CSS Sprites 圆角制作教程
关于css @import url()总结
一个非常精典的纯CSS漫画,登峰造极.
css 背景透明 实现代码
css 横排 实现代码
CSS 像素图制作攻略
CSS 实现绝对底部一个完美解决方案
CSS 代码质量提高的10条实用技巧
CSS 扑克牌效果实现代码
margin 负值引起的层级(z-index)问题
关于Firefox下截取后省略号的问题
14个华丽的javascript图表资源和插件
IE img多余5像素空白解决方法
css 不同媒介的显示样式控制方式
打印网页中不打印页面中的某些内容
CSS Sprites 图片整合技术分析
文字超过宽度显示省略号(无js全兼容)

CSS样式表 中的 用 CSS 让你的按钮(button)更加迷人


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 155 ::
收藏到网摘: n/a

查看演示
我们用 A 包含一个 SPAN 标签来实现此效果:
HTML:

代码如下:

<a class="button" href="#"><span>按钮文字</span></a>

设置按钮样式:

代码如下:

<style type="text/css">
a.button {
background: transparent url('bg_button_a.gif') no-repeat scroll top right;
color: #444;
display: block;
float: left;
font: normal 12px arial, sans-serif;
height: 24px;
margin-right: 6px;
padding-right: 18px; /* sliding doors padding */
text-decoration: none;
}
a.button span {
background: transparent url('bg_button_div.gif') no-repeat;
display: block;
line-height: 14px;
padding: 5px 0 5px 18px;
}
</style>

为按钮添加点击样式:

代码如下:

<style type="text/css">
a.button:active {background-position: bottom right; color: #000; outline: none; /* hide dotted outline in Firefox */ }
a.button:active span { background-position: bottom left; padding: 6px 0 4px 18px; /* push text down 1px */ }
</style>

由于 IE 下点击后不能还原到默认状态,因此,我们需要在标签里添加一段代码:
<a class="button" href="#" onclick="this.blur(); return false;"><span>按钮文字</span></a>
如果你需要用它提交表单(FORM),那么可以在 onclick 里面添加一个提交语句,如:document.forms['theForm'].submit();