html - 绝对定位元素在使用过滤器的活动时丢失位置
问题描述
我遇到了以下我在以下示例中重新创建的奇怪情况:
.relative {
position: relative;
}
.absolute {
position: absolute;
left: 50%;
top: 100%;
}
a:active {
filter: brightness(130%);
}
<div class="relative">
<a href="//google.com"><img class="absolute" src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/23/Sternbergia_lutea_showing_the_different_parts_of_the_flower.JPG/130px-Sternbergia_lutea_showing_the_different_parts_of_the_flower.JPG" /></a>
</div>
在单击 mousedown 事件时,会触发:active
具有该属性的伪类,filter
而图像会丢失其绝对位置,因此甚至不会跟踪链接。我在任何地方都找不到任何关于它的信息,有人知道为什么会这样吗?
解决方案
我也不明白它的确切原因。但是,您要做的是将过滤器应用于 img 而不是标签。也许标签上的行为未定义:
.relative {
position: relative;
}
.absolute {
position: absolute;
left: 50%;
top: 100%;
}
a:active img {
filter: brightness(130%);
}
<div class="relative">
<a href="//google.com"><img class="absolute" src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/23/Sternbergia_lutea_showing_the_different_parts_of_the_flower.JPG/130px-Sternbergia_lutea_showing_the_different_parts_of_the_flower.JPG" /></a>
</div>
这解决了它。
推荐阅读
- javascript - 去抖动以减少函数调用
- java - 从 RGB 中去除灰色。我正在使用珊瑚学习编程+课程的一部分
- html - Flutter:FormatException:意外字符(在字符1处)HTML
- flutter - Flutter BoxShadow 重叠兄弟
- tensorflow - 当最小化损失时,变量 ['Variable:0'] 不存在张量流梯度
- spring-boot - Spring-Boot-Maven-Plugin 问题“无法转移”
- kubernetes - 如何在 azure devops 上运行启动 kubernetes 集群的脚本
- keycloak - View-users 权限只查看部分用户
- webpack - 如何解决 Create-React-app 项目中的块加载错误?
- python - 如何捕捉终端输出?