这个图像可以是css框阴影渐变吗?

时间:2013-06-17 12:10:58

标签: gradient css3 css

我可以使用box-shadow制作吗?现在它是一个图像,但如果可以用css box-shadow完成,我就会受伤。

the shadow I want

3 个答案:

答案 0 :(得分:6)

工作小提琴:http://jsfiddle.net/sinhayash/7dPnQ/1/

.class {
    height: 100px;
    width: 100px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;        
border-top: 3px solid rgb(16, 130, 253);
    border-bottom: 3px solid rgb(179, 216, 255);
    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(rgb(16, 130, 253)), to(rgb(179, 216, 255)));
    background-image: -webkit-linear-gradient(#000, rgb(179, 216, 255));
    background-image:
        -moz-linear-gradient(rgb(16, 130, 253), rgb(179, 216, 255)),
        -moz-linear-gradient(rgb(16, 130, 253), rgb(179, 216, 255));
    background-image:
        -o-linear-gradient(rgb(16, 130, 253), rgb(179, 216, 255)),
        -o-linear-gradient(rgb(16, 130, 253), rgb(179, 216, 255));
    background-image: 
        linear-gradient(rgb(16, 130, 253), rgb(179, 216, 255)),
        linear-gradient(rgb(16, 130, 253),rgb(179, 216, 255));
    -moz-background-size: 3px 100%;
    background-size: 3px 100%;
    background-position: 0 0, 100% 0;
    background-repeat: no-repeat;
}

使用firefox和chrome。

答案 1 :(得分:1)

我不相信box-shadow可以做到这一点,但可以通过边框和背景渐变的组合来完成。

DEMO

div { 
    width: 400px;
    padding: 20px 25px;
    border-top: 5px solid #4672bb;
    border-bottom: 5px solid #b8c9e5;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;
    border-radius: 5px;
    margin: 40px auto;
    background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0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Q+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
    background-image: -webkit-linear-gradient(#4672bb, #b8c9e5);
    background-image:
        -moz-linear-gradient(#4672bb, #b8c9e5),
        -moz-linear-gradient(#4672bb, #b8c9e5)
    ;
    background-image:
        -o-linear-gradient(#4672bb, #b8c9e5),
        -o-linear-gradient(#4672bb, #b8c9e5)
    ;
    background-image: 
        linear-gradient(#4672bb, #b8c9e5),
        linear-gradient(#4672bb, #b8c9e5)
    ;
    -moz-background-size:5px 100%;
    background-size:5px 100%;
    background-position:0 0, 100% 0;
    background-repeat:no-repeat;
}

使用精彩的ColorZilla Gradient Generator

生成SVG

答案 2 :(得分:0)

您可以将图像用作边框图像: http://jsfiddle.net/RRpcD/ jsfiddle不喜欢这张图片?关于codepen:http://codepen.io/gcyrillus/pen/Awihd

.gradient-border {
    border-style: solid;
    border-width: 2px 4px 4px 3px;
    -moz-border-image: url(http://i.stack.imgur.com/O87Qx.png) 2 4 4 3 stretch;
    -webkit-border-image: url(http://i.stack.imgur.com/O87Qx.png) 2 4 4 3 stretch;
    -o-border-image: url(http://i.stack.imgur.com/O87Qx.png) 2 4 4 3 stretch;
    border-image: url(http://i.stack.imgur.com/O87Qx.png) 2 4 4 3 fill stretch;
}