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

CSS样式表
CSS选择器支持列表
CSS基础教程:CSS样式表与具体设备
再谈动态添加样式规则
CSS模型教程:boxes,borderes,margins和padding
IE中选择符的4095限制
Jacascript和CSS实现Mac OS导航菜单
CSS网页制作教程:网页首页设计实例
CSS教程:CSS制作漂亮的灵活的图表
css框架是什么
推荐一份不错的reset.css
IE7下position:relative的问题
WEB标准的思想是什么?
优先选择W3C推荐的标准规范
CSS教程:彻底掌握Z-index属性
CSS高级技巧:圆角矩形
css对于字体和背景等属性的控制
CSS实现网页表格行鼠标滑过高亮显示
CSS3的border-radius属性定义HTML元素的圆角
Web流程图绘制的心得
CSS网页布局教程:绝对定位和相对定位

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


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