css - 背景剪辑:文本不适用于转换后的子元素
问题描述
我正在尝试使用background-clip: text
,同时也在具有背景的元素内转换了子元素,但是一旦我添加transform
(或者position: relative
- 我也确定更多的东西)到孩子们background-clip: text
就可以开始工作了。
为什么会这样?有没有办法绕过它?
document.querySelector('h1').addEventListener('click', function (e) {
this.classList.toggle('alt');
});
h1 {
background: red;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
h1.alt span {
display: inline-block;
transform: translateY(1rem);
}
<h1>
<span>H</span><span>e</span><span>l</span><span>l</span><span>o</span>
</h1>
<p>Click the heading to change the spans from no transform to transform.</p>
解决方案
推荐阅读
- javascript - 如何获得价值
没有 jQuery - python - git pretty format 命令不输出正确的 json 文件
- python - 为什么“k”的值没有增加?
- javascript - 在 html 表中从数据库中拆分值
- linux - MINICOM TTY 通信和 HEX 转换
- kubernetes - gpu 工作节点无法加入集群
- r - 有没有办法根据分类列和日期列过滤 R 中的行
- excel - 如何在特定工作表中运行宏,但根据从另一个 Excel 文件/工作表维护的值控制开始?
- python - Python 条件拆分
- sql - 如何在 SQL 中的物化视图左侧添加序列?