【问题标题】:Strange behaviour when combine filter and :hover in Chrome在 Chrome 中组合过滤器和 :hover 时的奇怪行为
【发布时间】:2019-11-28 10:41:54
【问题描述】:

有人可以解释为什么会这样吗? 当我同时使用transform 和filter 时,溢出属性将不起作用并出现角落。这是错误还是我遗漏了什么? 没有filter 一切都好。在 Mozilla 中一切正常。

<div class="wrap">
    <div class="image"></div>
</div>

<style>
.wrap{
    width: 200px;
    height: 200px;
    overflow: hidden;
    border: 1px solid;
    border-radius: 15px;
}
.image{
    background: url(https://interactive-examples.mdn.mozilla.net/media/examples/grapefruit-slice-332-332.jpg);
    background-position: center;
    background-size: cover;
    width: 100%;
    height: 100%;
    transition: all 1s ease-out;
}
.image:hover{
    -webkit-transform: scale(1.2, 1.2);
    transform: scale(1.2, 1.2);
    -webkit-filter: saturate(1.7) brightness(1.05);
    filter: saturate(1.3) brightness(1.07);
}
</style>


https://jsfiddle.net/mith1408/nmvozkhd/2/

UPD。 如果没有transform 而只有filter,则会继续出现此错误。 所以,问题不在组合中:transform 和 filter。

UPD2. 像这样的外观是非常古老的错误,已修复但仅适用于被动元素。当您应用:hover 时,错误再次出现在过渡时刻。 Border radius and overflow hidden fail when CSS filter is applied in Chrome

旧主题的示例,修改为使用:hover https://jsfiddle.net/mith1408/xk1hf3wq/3/

【问题讨论】:

  • 可能的解决方案:分离属性 - 1. 对包装器应用“过滤器” 2. 仅对图像应用“转换”。此处示例:jsfiddle.net/mith1408/nmvozkhd/4 但有趣的是找到问题的根源。
  • 我认为该错误仅与filter 属性有关,我禁用了transform 更改并且错误仍然存​​在
  • 你说得对,很奇怪..
  • 不,这是不同的主题,因为在您的示例中,错误出现在被动元素上。(看起来它已修复)。在我的示例中,当应用 ":hover" 伪类时会出现错误。并处于过渡时刻。

标签: css google-chrome


【解决方案1】:

您的问题可能与堆叠上下文有关。两者 - 转换和过滤器在应用时都会创建堆叠上下文。这是我的第一个想法。

您可以在此处阅读更多内容: MDN the stacking context

这里: stacking contexts: What they are and how they work

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多