一个专注于技术的IT男
炫酷CSS超链接按钮一
上一篇文章提到用CSS分割图片的技巧,例子中也展示了一个很漂亮的CSS按钮,今天在tutorialzine看到这篇教程 Sweet AJAX Tabs With jQuery 1.4 & CSS3的按钮也很漂亮,把demo代码下载下来之后,看了一下也是用CSS定位分割图片的技巧做出来的,和上一篇文章中按钮实现略有不同,下面就来解析怎么做出如下的效果:
首先按钮的HTML代码,
<a class="green" href="#">Tab two <span class="left"></span><span class="right"></span></a>
这个按钮的图片由左中右三部分构成,两边的图片是做好了边框效果的,中间的图片可以无限扩展。即下图显示的效果(注:图像来源于tutorialzine原教程)
源图像是这样的,其实还分成了亮度有区别的上下两部分,使用上文中已经介绍过的CSS技巧达到鼠标移上去高亮的效果。
->
->
->
让我们来看看实现一个按钮核心的CSS代码:
a.blue{background:url(img/blue_mid.png) repeat-x top center; color:#03426e;}
a.blue span.left{ background:url(img/blue_left.png) no-repeat left top;}
a.blue span.right{ background:url(img/blue_right.png) no-repeat right top;}
然后是定义按钮size、边框、边距等的CSS代码:
a,a:visited{
/* Styling the hyperlinks of the tabs as colorful buttons */
float:left;
font-size:18px;
/* display:block allows for additinal CSS rules to take effect, such as paddings: */
display:block;
padding:7px 16px 1px;
margin:4px 5px;
height:29px;
/* Giving positioning */
position:relative;
/* CSS3 text-shadow */
text-shadow:1px 1px 1px #CCCCCC;
}
.left{
/* The left span in the hyperlink */
height:37px;
left:0;
position:absolute;
top:0;
width:10px;
}
.right{
/* The right span in the hyperlink */
height:37px;
right:0;
position:absolute;
top:0;
width:10px;
}
| 打印文章 | 这篇文章由Jacky于2010/01/27 21:25发表在CSS, WebDev。你可以订阅RSS 2.0 也可以发表评论或引用到你的网站。 |


