CSS:如何创建与iOS图标类似的反射光泽的按钮?

时间:2011-10-28 15:32:44

标签: css button

我正在尝试使用CSS设置HTML按钮的样式,以便它们像iOS设备主页上的图标一样具有反射光泽。 Apple会自动执行此操作,如here所示。我需要类似CSS中闪耀的东西。

2 个答案:

答案 0 :(得分:13)

看看this fiddle

以下是代码:

HTML:

<div class="icon">
    <div class="shine"></div>
</div>

和CSS:

.icon {
    width: 150px;
    height: 150px;
    border-radius: 30px;
    background: red;
    float: left;
    margin: 50px;
    box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.5);
}
.shine {
    background: -moz-linear-gradient(top, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0.2) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,0.7)), color-stop(100%,rgba(255,255,255,0.2))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, rgba(255,255,255,0.7) 0%,rgba(255,255,255,0.2) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, rgba(255,255,255,0.7) 0%,rgba(255,255,255,0.2) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, rgba(255,255,255,0.7) 0%,rgba(255,255,255,0.2) 100%); /* IE10+ */
    background: linear-gradient(top, rgba(255,255,255,0.7) 0%,rgba(255,255,255,0.2) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b3ffffff', endColorstr='#33ffffff',GradientType=0 ); /* IE6-9 */
    height: 90px;
    width: 150px;
    box-shadow: inset 0px 2px 1px rgba(255, 255, 255, 0.7);
    border-top-right-radius: 30px;
    border-top-left-radius: 30px;
    border-bottom-right-radius: 100px 40px;
    border-bottom-left-radius: 100px 40px;
}

答案 1 :(得分:5)

我的示例使用背景颜色:红色而不是图像,但只是将任何图像作为背景放在#icon div中,它也应该有效。

(顺便说一句,我使用了这个很棒的网站:http://www.colorzilla.com/gradient-editor/用于渐变)

HTML:

<div class="icon">
    <div class="shine">
    </div>
</div>

CSS:

.icon {
    width:50px;
    height:50px;
    background-color: red;
    overflow: hidden;
    position: relative;
}
.shine {
    position: absolute;
    top: -70px;
    left: -25px;
    width:100px;
    height:100px;
    border-radius: 50px;

    background: -webkit-radial-gradient(center, ellipse cover,  rgba(255,255,255,1) 0%,rgba(255,255,255,0) 150%); /* Chrome10+,Safari5.1+ */
    background: -moz-radial-gradient(center, ellipse cover,  rgba(255,255,255,1) 0%, rgba(255,255,255,0) 150%); /* FF3.6+ */
    background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(255,255,255,1.5)), color-stop(100%,rgba(255,255,255,0))); /*     Chrome,Safari4+ */
    background: -o-radial-gradient(center, ellipse cover,  rgba(255,255,255,1) 0%,rgba(255,255,255,0) 150%); /* Opera 12+ */
    background: -ms-radial-gradient(center, ellipse cover,  rgba(255,255,255,1) 0%,rgba(255,255,255,0) 150%); /* IE10+ */
    background: radial-gradient(center, ellipse cover,  rgba(255,255,255,1) 0%,rgba(255,255,255,0) 150%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#00ffffff',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
}

希望它适合你!