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

CSS样式表
css分页样式代码
用css filter做鼠标滑过图片效果
有关于IE8 Beta 1两个提醒
css Hspace 和vspace的图片控制实例
firefox background-image垂直平铺问题的解决方法
发一个css比较清爽的写法
htm页面中<a name>加name和id的冲突附解决方法
javascript 获取特定的 CSS属性值
CSS教程之CSS的应用
html页面head区域的编码书写规范
html滚动条样式
不用图片作背景CSS做的小灯笼效果_练习用
网页绿色系配色应用实例图文
网页中英文混排行高不等问题的解决方法
CSS Hack 汇总速查手册浏览器兼容必会
css文本框与按钮美化效果代码
网页设计中的 serif 和 sans-serif字体应用
采用XHTML和CSS设计可重用可换肤的WEB站点的方法
CSS 浏览器的等宽空格问题解决
欲练CSS ,必先解决IE的一些细节分析

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


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