问题
I'm trying to add a box shadow to #main-content-area
on the top side and 50% to both the left and right sides (from top), but it is not working.
What is wrong with my code?
.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>
回答1:
Just for showing box-shadow I have removed the position: absolute;
you can position your div as per your requirement.
.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>
回答2:
use width "halfshadow" div or place content. Here is example with added "width"
.halfshadow {
position: absolute;
z-index: -1;
top: 0;
height: 50%;
width: 100%;
box-shadow: 1px 0px 10px rgba(0, 0, 0, 0.5);
}
回答3:
Remove position: absolute;
from .halfshadow
class
回答4:
you need to mention div tag
.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;
}
来源:https://stackoverflow.com/questions/41391849/box-shadow-not-working