盒子阴影不起作用

时间:2016-12-30 06:43:29

标签: css box-shadow

我正在尝试在顶部向#main-content-area添加一个框阴影,向左侧和右侧添加50%(从顶部),但它不起作用。

我的代码出了什么问题?

.wrapper {
  position: relative;
}
#main-content-area {
  position: relative;
  background-color: white;
  margin: -80px auto auto auto;
  z-index: 4;
  border: 1px solid red;
}
.halfshadow {
  position: absolute;
  z-index: -1;
  top: 0;
  height: 50%;
  box-shadow: 1px 0px 10px rgba(0, 0, 0, 0.5);
}
<div class="wrapper">
  <div class="line"></div>
  <div class="row">
    <div class="col-sm-2">
    </div>
    <div class="col-sm-8" id="main-content-area">

      <div class="row">
        <div class="col-sm-4">
          <img src="me.jpg" class="img-responsive" />
        </div>

        <div class="col-sm-4">
          <img src="me.jpg" class="img-responsive" />
        </div>

        <div class="col-sm-4">
          <img src="me.jpg" class="img-responsive" />
        </div>
      </div>

    </div>
    <div class="halfshadow"></div>

    <div class="col-sm-2">
    </div>
  </div>
</div>

4 个答案:

答案 0 :(得分:1)

只是为了显示框阴影,我删除了position: absolute;,您可以根据自己的要求定位div。

&#13;
&#13;
.wrapper{
  position:relative;
}

#main-content-area{
  position:relative;
  background-color:white;
  margin: -80px auto auto auto;
  z-index:4;
  border:1px solid red;
}
 
.halfshadow{
  z-index:-1;
  height: 50px;
  width: 100%;
  box-shadow: 1px 0px 10px rgba(0, 0, 0, 0.5);
}
&#13;
<div class="wrapper">
  <div class="line"></div>
  <div class="row" >
    <div class="col-sm-2"></div>
    <div class="col-sm-8" id="main-content-area">
      <div class="row">
        <div class="col-sm-4">
          <img src="me.jpg" class="img-responsive"/>
        </div>
        <div class="col-sm-4">
          <img src="me.jpg" class="img-responsive"/>
        </div>
        <div class="col-sm-4">
          <img src="me.jpg" class="img-responsive"/>
        </div>
      </div>
    </div>
    <div class="halfshadow"></div>
    <div class="col-sm-2" ></div>
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

使用width“halfshadow”div或放置内容。这是添加“宽度”

的示例
.halfshadow {
position: absolute;
z-index: -1;
top: 0;
height: 50%;
width: 100%;
box-shadow: 1px 0px 10px rgba(0, 0, 0, 0.5);
}

答案 2 :(得分:0)

你需要提到div标签

.div1
{
  padding: 28px 10px;
  /* width: 230px; */
  width:200px;
  /*  margin-right: 31px;
  margin-left: 105px;*/
  margin-top:10px;
  height: 226px;
  box-shadow: 10px 10px 5px #888888;
  margin-top: -20px;
  color: blue;
  text-align: center;
}

答案 3 :(得分:0)

position: absolute;

中删除.halfshadow