codetc - 网站开发技术 首页 代码 CSS 查看内容

纯CSS实现渐变圆角按钮

2014-11-3 09:27| 发布者: CODETC| 查看: 2881| 评论: 0

HTML5+CSS3 代表着下一代web开发技术,虽然标准规范还没有正式发布,但是未来的发展前景已经可以预见。

随着越来越多的主流浏览器对这些标准的支持,我们已经可以使用其中一些技术来美化页面了。例如下面要讲的自定义渐变圆角按钮样式,虽然有些浏览器还不支持,但我们有折中的方法,为这些不支持 CSS3 渐变圆角功能的浏览器提供降级方案。

不必再通过图片来创造具有渐变圆角效果的按钮,会方便很多。

首先来看下样式在各个浏览器中的效果:

Chrome,Safari,Firefox,Opera下的效果,完美支持!


IE9下的效果,仅支持圆角!


IE7、IE8下的效果,圆角渐变都不支持!


IE低版本真的很令人头疼,网上也有实现IE下渐变圆角效果的方法,比较繁琐。个人觉得没有必要,这个样式看起来还不错,也没有影响布局,可以就这样使用!

核心代码如下:

HTML 代码
<div class="main">
        <!--css3自定义渐变圆角按钮样式-->
            <input type="submit" class="btn-style-01" value="提交" />
        <!--css3自定义渐变圆角按钮样式-->
</div>
CSS 代码
.btn-style-01{
    border-style:none;
    padding:8px 30px;
    line-height:24px;
    color:#fff;
    font:16px "Microsoft YaHei", Verdana, Geneva, sans-serif;
    cursor:pointer;
    border:1px #ae7d0a solid;
    -webkit-box-shadow:inset 0px 0px 1px #fff;
    -moz-box-shadow:inset 0px 0px 1px #fff;
    box-shadow:inset 0px 0px 1px #fff;/*内发光效果*/
    -webkit-border-radius:4px;
    -moz-border-radius:4px;
    border-radius:4px;/*边框圆角*/
    text-shadow:1px 1px 0px #b67f01;/*字体阴影效果*/
    background-color:#feb100;
    background-image: -webkit-gradient(linear, 0 0%, 0 100%, from(#feb100), to(#e8a201));
    background-image: -webkit-linear-gradient(top, #feb100 0%, #e8a201 100%);
    background-image: -moz-linear-gradient(top, #feb100 0%, #e8a201 100%);
    background-image: -ms-linear-gradient(top, #feb100 0%, #e8a201 100%);
    background-image: -o-linear-gradient(top, #feb100 0%, #e8a201 100%);
    background-image: linear-gradient(top, #feb100 0%, #e8a201 100%);/*颜色渐变效果*/
}
.btn-style-01:hover {
    background-color:#e8a201;
    background-image: -webkit-gradient(linear, 0 0%, 0 100%, from(#e8a201), to(#feb100));
    background-image: -webkit-linear-gradient(top, #e8a201 0%, #feb100 100%);
    background-image: -moz-linear-gradient(top, #e8a201 0%, #feb100 100%);
    background-image: -ms-linear-gradient(top, #e8a201 0%, #feb100 100%);
    background-image: -o-linear-gradient(top, #e8a201 0%, #feb100 100%);
    background-image: linear-gradient(top, #e8a201 0%, #feb100 100%);
}
文章来源 CODETC,欢迎分享,转载请注明地址: http://www.codetc.com/article-29-1.html

最新评论

 作为游客发表评论,请输入您的昵称

返回顶部