【发布时间】:2022-02-14 22:06:16
【问题描述】:
我有一个右下角倾斜的元素,我必须在其上放置一个盒子阴影。有时倾斜的角落会被徽章覆盖 - 如果是这种情况,我的问题不适用:
这是信息框及其角落的 (s)css 部分(还有一些样式,但它们只是文本修饰符...整个内容都在 codepen 上:https://codepen.io/kerowan/pen/bqMOeB
.product-info-wrapper {
position: absolute;
top: 150px;
max-width: 100%;
padding-bottom: 10px;
width: 100%;
.product-info {
position: relative;
padding: 1rem * .5;
padding-right: 1rem * 2;
overflow: hidden;
box-shadow: 0 0 5px;
&:before,
&:after {
position: absolute;
content: "";
left: 0;
z-index: -1;
background-color: lighten(#000, 93.5%);
border-color: lighten(#000, 93.5%);
}
&:before {
top: 0;
right: 0;
bottom: 35px;
}
&:after {
top: auto;
right: -5px;
bottom: 0;
border-style: solid;
border-width: 35px 35px 0 0;
background-color: transparent;
border-right-color: transparent;
}
}
}
如何做到这一点(沿着斜角移动阴影)?如果倾斜角是按照我的方式生成的,可以做到吗?由于relative 和absolute 的所有定位,我有点依赖这些类(至少我认为),我需要放置角徽章。
编辑:一些 HTML,如果你需要的话:
<div class="swiper-slide">
<div class="product-info-wrapper">
<div class="product-info">
<div class="row no-gutters">
<div class="col-8">
<strong class="text-uppercase">Amino Force</strong>
<span class="product-info-link"><a href="#">Kurzinfo</a></span>
</div>
<div class="col-4 text-right">
<span class="product-info-price">CHF 34.00</span>
</div>
</div>
</div>
</div>
</div>
<div class="swiper-slide">
<div class="product-info-wrapper">
<div class="product-info">
<div class="row no-gutters">
<div class="col-8">
<strong class="text-uppercase">Amino Force</strong>
<span class="product-info-link"><a href="#">Kurzinfo</a></span>
</div>
<div class="col-4 text-right">
<span class="product-info-price">CHF 34.00</span>
</div>
</div>
</div>
<div class="product-badge-wrapper">
<div class="product-badge red">
<div class="product-badge-content">
new
</div>
</div>
</div>
</div>
</div>
这只是整个 HTML 代码的一部分,可以在 codepen thingy 上找到。但我猜想,这将是唯一相关的部分。如果您需要更多,请告诉我!
EDIT2
此信息框的内容可以展开。如果我点击“Kurzinfo”,它会展开并显示更多信息。这不在 codepen 版本上,因为我在添加扩展功能之前创建了它。
【问题讨论】:
-
您可以使用图像作为框的背景,并在 Paint.NET 中制作图像 - 在图像中包含阴影
-
@AnishGoyal 这个
product-info东西的内容必须是灵活的,当我点击“Kurzinfo”时,它会扩展......将其添加到问题中。我觉得在这种情况下使用背景图片不起作用 -
如果你让一个绝对定位(给你的盒子相对定位)一个等效的盒子,但是黑色,z-index -1,作为一个伪阴影?你会失去传播,但我认为 CSS 不会让你做你想做的事。