CSS 变换缩放忽略 z-index 和渐变

CSS transform scale ignor z-index and gradient

我在::after上使用linear-gradient来制作一个这样的object,一个消失的边框。现在我想使用 scale 使其中之一如此活跃(选中)但看起来它忽略 z-index: -1; 并显示所有渐变。我想像其他人一样显示选定的一个。

.Winter-Plans {
    width: calc(100%/5 - 16px);
    min-height: 360px;
    position: relative;
    border-radius: 20px;
    background: white;
    padding: 80px 15px 35px 15px;
    margin: 0 8px 20px 8px;
    box-sizing: border-box;
    float: left;
}

.Winter-Plans::after {
    position: absolute;
    top: -1px;
    bottom: -1px;
    left: -1px;
    right: -1px;
    background: linear-gradient(to top, #ddd, white);
    content: '';
    z-index: -1;
    border-radius: 20px;
}

.Winter-Plans.Selected {
    transform: scale(1.1);
}
<div class="Winter-Plans">
</div>
<div class="Winter-Plans Selected">
</div>
<div class="Winter-Plans">
</div>

这个标题有很多主题,我试过了,但其中 none 解决了我的问题。 ps:我无法更改 html 结构,因此我使用了 ::after

transform 将创建一个堆叠上下文,强制将伪元素绘制在不再 outside/behind 您的元素内。相关问题以更好地理解问题:

考虑使用不需要伪元素的多个背景来实现相同效果的不同方法

.Winter-Plans {
    width: calc(100%/5 - 16px);
    min-height: 360px;
    border-radius: 20px;
    background: 
      linear-gradient(white,white)         padding-box, /* cover only the padding area*/
      linear-gradient(to top, #ddd, white) border-box;  /* cover the border area*/
    border:1px solid transparent; /* a transparent border for our gradient */
    padding: 80px 15px 35px 15px;
    margin: 0 8px 20px 8px;
    box-sizing: border-box;
    float: left;
}

.Winter-Plans.Selected {
    transform: scale(1.1);
}
<div class="Winter-Plans">
</div>
<div class="Winter-Plans Selected">
</div>
<div class="Winter-Plans">
</div>

如果您需要具有透明背景和带半径的边框渐变的解决方案,请检查: