如何使用css3在圆角元素后面实现圆角阴影

时间:2013-09-06 20:34:19

标签: html css css3

我想让元素看起来像这个图像

Round shadow on element

我已经尝试了很多在css中做这种影子,最后想想为什么不向社区询问它,无论是否可能。

我知道box-shadow表示盒子上有阴影。有类似round-shodow

的东西

我希望它在css3中没有任何图像。 可能吗?如果是,那怎么可能呢?如果没有好的话。

我非常了解box-shadowborder-radius所以请不要告诉我有关这些事情,再次检查其不同的阴影

3 个答案:

答案 0 :(得分:5)

这至少是一个起点。您可以使用before(和after)伪元素。 http://jsfiddle.net/FHLJM/

div {
    background-color: #f00;
    border-radius: 50%;
    height: 250px;
    width: 250px;
    margin: 30px auto;
    position: relative;
    z-index: 1;
}
div:before {
    content: '';
    height: 150px;
    width: 250px;
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#000), to(#fff));;
    position: absolute;
    top: 100px;
    right: 50px;
    -webkit-transform: rotate(45deg);
    z-index: -1;
}
div:after {
    content: '';
    height: 100%;
    width: 100%;
    border-radius: 50%;
    background: #f00;
    position: absolute;
    z-index: 1;
}

同样,它无论如何都不是一种完美的方法,但它能够在某种程度上完成你正在寻找的东西。

答案 1 :(得分:1)

如果想要一个简单的方法用JS做这个,我已经非常幸运了

https://github.com/heyimjuani/iluminate

答案 2 :(得分:0)

好的,这里有一些css可以帮助你了解你所要求的效果:

.circle { background: red; border-radius: 50%; width: 50px; height:50px;position:relative;}
.circle:before {
    background: -moz-linear-gradient(top, rgba(136,136,136,0.4) 0%, rgba(136,136,136,0) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(136,136,136,0.4)), color-stop(100%,rgba(136,136,136,0))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, rgba(136,136,136,0.4) 0%,rgba(136,136,136,0) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, rgba(136,136,136,0.4) 0%,rgba(136,136,136,0) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, rgba(136,136,136,0.4) 0%,rgba(136,136,136,0) 100%); /* IE10+ */
    background: linear-gradient(to bottom, rgba(136,136,136,0.4) 0%,rgba(136,136,136,0) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#66888888', endColorstr='#00888888',GradientType=0 ); /* IE6-9 */
    width:100%;
    height:75%;
    display: block;
    content: " ";
    position: relative;
    top: 22px;
    right: 15px;
    z-index: -1;
    -webkit-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    transform:rotate(45deg);
}

小提琴:http://jsfiddle.net/RKwdj/