box-shadow在我的图像元素上不起作用-我说的是.card img:nth-child(1)。这是我的HTML代码:
.card {
display: flex;
flex-flow: column wrap;
align-items: center;
}
.card img:nth-child(1) {
height: 220px;
width: 100%;
object-fit: cover;
box-shadow: 0px 10px 5px 0px rgba(0, 0, 0, 0.75);
clip-path: polygon(0 0, 100% 0, 100% 86%, 63% 100%, 28% 87%, 0 100%);
}
.card img:nth-child(2) {
height: 150px;
width: 150px;
object-fit: cover;
border-radius: 50%;
border: 10px solid #fff;
box-shadow: 5px 0 10px rgba(0, 0, 0, .7);
margin-top: -40%;
z-index: 2;
}
<div class="card">
<!--img src="img/card-bg1.jpg"-->
<img src="https://via.placeholder.com/550" />
<!-- I'm talking about this image -->
<!--img src="img/profile1.jpg"-->
<img src="https://via.placeholder.com/150" />
<h2>Jane Smith</h2>
<p>FrontEnd Developer</p>
<p>Esdsdsd.</p>
<button type="button">Message me!</button>
</div>
为什么不起作用?
框阴影也正确地应用在第二张图像上,但是您正在使用clip-path
属性对其进行裁剪
.card {
display: flex;
flex-flow: column wrap;
align-items: center;
}
.card img:nth-child(1) {
height: 220px;
width: 100%;
object-fit: cover;
box-shadow: 0px 10px 5px 0px rgba(0, 0, 0, 0.75);
}
.card img:nth-child(2) {
height: 150px;
width: 150px;
object-fit: cover;
border-radius: 50%;
border: 10px solid #fff;
box-shadow: 5px 0 10px rgba(0, 0, 0, .7);
margin-top: -40%;
z-index: 2;
}
<div class="card">
<img src="img/card-bg1.jpg">
<!-- I'm talking about this image -->
<!--img src="img/profile1.jpg"-->
<img src="https://via.placeholder.com/150" />
<h2>Jane Smith</h2>
<p>FrontEnd Developer</p>
<p>Esdsdsd.</p>
<button type="button">Message me!</button>
</div>
只需从clip-path: polygon(0 0, 100% 0, 100% 86%, 63% 100%, 28% 87%, 0 100%);
中删除.card img:nth-child(1)
。
.card {
display: flex;
flex-flow: column wrap;
align-items: center;
}
.card img:nth-child(1) {
height: 220px;
width: 100%;
object-fit: cover;
box-shadow: 0px 10px 5px 0px rgba(0, 0, 0, 0.75);
}
.card img:nth-child(2) {
height: 150px;
width: 150px;
object-fit: cover;
border-radius: 50%;
border: 10px solid #fff;
box-shadow: 5px 0 10px rgba(0, 0, 0, .7);
margin-top: -40%;
z-index: 2;
}
<div class="card">
<img src="img/card-bg1.jpg">
<!-- I'm talking about this image -->
<!--img src="img/profile1.jpg"-->
<img src="https://via.placeholder.com/150" />
<h2>Jane Smith</h2>
<p>FrontEnd Developer</p>
<p>Esdsdsd.</p>
<button type="button">Message me!</button>
</div>