【发布时间】:2021-08-08 22:13:42
【问题描述】:
我正在 CSS 中尝试一个东西,其中文本的背景是图像,当我们将鼠标悬停在文本上时,它会缩放到一个非常大的数字,用作字体颜色的图像完全显示出来。它在 Mozilla Firefox 上完美运行,但 CSS 的 transform 属性在 Chrome 上似乎被破坏了,文本在 Chrome 上悬停时消失了。
/* font */
@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@900&display=swap');
/* reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Rubik', sans-serif;
}
body,
html {
min-height: 100vh;
width: 100vw;
overflow-x: hidden;
background: #999;
}
/* styling */
.container {
background: url("https://picsum.photos/900/800");
background-repeat: no-repeat;
background-size: cover;
color: transparent;
-webkit-background-clip: text;
background-clip: text;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.container .image-text {
font-size: 5em;
font-weight: normal;
text-align: center;
transition: transform 2s linear;
}
.container .image-text:hover {
transform: scale(200);
}
<div class="container">
<div class="image-text">
Hover
</div>
</div>
【问题讨论】:
-
Chrome 有什么解决方法吗?
-
试试这个 SO 帖子:stackoverflow.com/questions/25372315/…
-
@PeterS 虽然 Chrome 不支持这样的缩放,但我相信 transform: scale(..) 是并且这似乎是这里使用的(或者是在编辑?)
-
PeterS 正在查看错误的属性。它是caniuse.com/transforms2d,表示支持
transform: scale(x, y),另见mdn
标签: html css google-chrome css-transforms