在<div> </div>的所有四个边上使用线性渐变

时间:2014-07-15 21:29:50

标签: css

我正在尝试使用线性渐变来设置框的样式。我希望在所有四个方面都有从红色到白色的7px淡入淡出。到目前为止,我有一方(底部)工作,没有问题:

background: -webkit-linear-gradient(bottom, white, #eb3136 7px); 
background: -o-linear-gradient(bottom, white, #eb3136 7px); 
background: -moz-linear-gradient(bottom, white, #eb3136 7px); 
background: linear-gradient(bottom, white, #eb3136 7px); 

如何在其他三方获得7px淡入淡出?

感谢您的帮助。

2 个答案:

答案 0 :(得分:4)

box-shadow: 0px 0px 7px #eb3136 inset;

可能会以更简单的方式做你想做的事。

小提琴:http://jsfiddle.net/6EREc/

答案 1 :(得分:1)

您可以尝试多种背景:

background:
    linear-gradient(to top, #eb3136, white 7px, transparent 7px),
    linear-gradient(to right, #eb3136, white 7px, transparent 7px),
    linear-gradient(to bottom, #eb3136, white 7px, transparent 7px),
    linear-gradient(to left, #eb3136, white 7px, transparent 7px); 

Demo