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

CSS样式表
用CSS实现鼠标单击特效
引入CSS样式的五种方式
用CSS实现文字变图象特效
expression将JS、Css结合起来
alt属性和title属性
CSS使用技巧20则
CSS重新定义项目符号和编号技巧
CSS编辑工具Topstyle轻松打造网页风格
深入探讨CSS中字体元素
CSS经典实用技巧18招
FCKeditor 实战技巧
China.com网站开发规范
小三角的做法与使用
网站首页head区代码规范
动态更改网页HTML元素(对象)内容
css静态滤镜 + A:Hover
解读absolute与relative
怎样管理好样式
2006.12.06更新 TopStyle剪辑库
又一个典型css实例

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 162 ::
收藏到网摘: 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();