我正在尝试在顶部的#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>

最佳答案

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



.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);
}

<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>

关于css - 框阴影不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41391849/

10-09 23:52