Css框阴影移动到顶部和左侧

时间:2016-10-13 11:44:25

标签: html css css3

enter image description here

CSS& HTML:



body {background:#ccc}

.box h3{
  text-align:center;
    position:relative;
    top:80px;
}
.box {
    width:70%;
    height:200px;
    background:#FFF;
    margin:40px auto;
}

.effect3
{
  position: relative;
}
.effect3:before
{
  z-index: -1;
  position: absolute;
  content: "";
  bottom: 15px;
  left: 10px;
  width: 50%;
  top: 80%;
  max-width:300px;
  background: #777;
  -webkit-box-shadow: 0 15px 10px #777;
  -moz-box-shadow: 0 15px 10px #777;
  box-shadow: 0 15px 10px #777;
  -webkit-transform: rotate(-3deg);
  -moz-transform: rotate(-3deg);
  -o-transform: rotate(-3deg);
  -ms-transform: rotate(-3deg);
  transform: rotate(-3deg);
}

<div class="box effect3">
<h3>Effect 3</h3>
</div>
&#13;
&#13;
&#13;

我正在尝试用阴影装饰一个盒子。

上面的css是阴影底部和左边(红色圆圈)。 什么可以应用于顶部和左侧的红色(红色箭头)?

4 个答案:

答案 0 :(得分:1)

body {
  background: #ccc
}

.box h3 {
  text-align: center;
  position: relative;
  top: 80px;
}

.box {
  width: 70%;
  height: 200px;
  background: #FFF;
  margin: 40px auto;
}

.effect3 {
  position: relative;
}

.effect3:before {
    z-index: -1;
    position: absolute;
    content: "";
    left: -46px;
    width: 20%;
    bottom: 15px;
    top: 25%;
    max-width: 300px;
    height: 20px;
    background: #777;
    -webkit-box-shadow: 0 15px 10px #777;
    -moz-box-shadow: 0 15px 10px #777;
    box-shadow: -10px -5px 10px #777;
    -webkit-transform: rotate(-93deg);
    -moz-transform: rotate(-93deg);
    -o-transform: rotate(-93deg);
    -ms-transform: rotate(-93deg);
    transform: rotate(-93deg);
}

我认为这就是你要求的......

答案 1 :(得分:1)

请将这些代码用于左上角的框阴影:

.effect3:before {
    z-index: -1;
    position: absolute;
    content: "";
    bottom: 15px;
    left: 3px;
    width: 18%;
    top: 24px;
    max-width: 300px;
    background: #777;
    -webkit-box-shadow: -8px 15px 10px #777;
    -moz-box-shadow: -8px 15px 10px #777;
    -webkit-transform: rotate(87deg);
    -moz-transform: rotate(87deg);
    transform: rotate(87deg);
 }

enter image description here

答案 2 :(得分:0)

left()

使用http://css3gen.com/box-shadow/生成

答案 3 :(得分:0)

使用after并更改before,如下所示:

.effect3:before {
    z-index: -1;
    position: absolute;
    content: "";
    left: 15px;
    width: 50%;
    bottom: 15px;
    top: 4%;
    max-width: 300px;
    height: 20px;
    background: #777;
    -webkit-box-shadow: 0 15px 10px #777;
    -moz-box-shadow: 0 15px 10px #777;
    box-shadow: -10px -5px 10px #777;
    -webkit-transform: rotate(-3deg);
    -moz-transform: rotate(-3deg);
    -o-transform: rotate(-3deg);
    -ms-transform: rotate(-3deg);
    transform: rotate(3deg);
}

.effect3:after {
    z-index: -1;
    position: absolute;
    content: "";
    bottom: 15px;
    left: 10px;
    width: 50%;
    top: 80%;
    max-width: 300px;
    background: #777;
    -webkit-box-shadow: 0 15px 10px #777;
    -moz-box-shadow: 0 15px 10px #777;
    box-shadow: 0 15px 10px #777;
    -webkit-transform: rotate(-3deg);
    -moz-transform: rotate(-3deg);
    -o-transform: rotate(-3deg);
    -ms-transform: rotate(-3deg);
    transform: rotate(-3deg);
}

Here is the JSFiddle demo