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

CSS样式表
CSS:提高网页在浏览器的渲染速度
css网页制作实用技巧9则
思考Web站点设计对类以及id的命名方式
CSS教程:关于网页图片的属性
CSS教程:元素层叠级别及z-index
div css在思路和流程上实现结构与表现的分离
CSS入门教程:网页首字下沉
IE6、IE7和FF的最简单的hack技巧
跨浏览器实现float:center
css技巧:经典CSS使用技巧几则
CSS教程:legend标签设定宽度
网站进行W3C XHTML1.0验证的经验
CSS教程:网页颜色的几种表示
网页CSS背景图片使用的测试结果
CSS网页布局:网页页面结构化
SPAN和DIV,Class与ID的区别汇总
xhtml css网页制作中问题解决的方式
div css与xhtml css是什么意思?
CSS样式表优化更整洁而简短
CSS设计网站导航菜单的优势

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


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