用 CSS 让你的按钮(button)更加迷人

这篇文章教你用 CSS 制作漂亮的有点击效果的按钮,明白了原理,相信你也可以制作更加丰富的效果。

用 CSS 让你的按钮(button)更加迷人 – 示例

我们用 A 包含一个 SPAN 标签来实现此效果:

<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();

本文翻译自:
http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html

为了方便学习,本文并未完整翻译,如果你有兴趣,请直接浏览原文。

关于 Artlover

有多年 web 开发经验,擅长领域 PHP / MySQL / CSS / Javascript / Zend Framework ,期望:在分享中共同成长。
此条目发表在 CSS 分类目录,贴了 , , 标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*


*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>