CSS 从左到右的文字宽度
CSS text width left to right
我正在尝试从左到右淡入类似于 answer found here 的文本,但希望文本隐藏在透明背景 div 而不是示例的白色背景后面。 CSS 这可能吗?原因是文本后面会有一个图像,我想淡入。
是的,您可以简单地通过在 @keyframes
上将 width
设置为 0 到 100%(如您问题中的示例)来显示文本的各个部分。
您可以通过一个小演示示例了解它的工作原理。点击零:
stripe.onclick = function() {
var sec = new Date().getSeconds() % 10;
stripe.classList.add('animate');
digit.classList.add('animate');
console.log();
};
#digit {
width: 20px;
overflow: hidden;
font: 32px "Courier New", monospace;
cursor: pointer;
transition: 2s linear width;
}
#stripe {
width: 20px;
transition: 2s linear width;
}
#stripe.animate {
width: 200px;
transition: 2s linear width;
}
#digit.animate {
width: 200px;
transition: 2s linear width;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Title</title>
<style>
</style>
</head>
<body>
<div id="digit"><span id="stripe">0123456789</span></div>
<script>
</script>
</body>
</html>
P.S.
JS 仅供测试。通过@keyframes 你不需要它们。
我正在尝试从左到右淡入类似于 answer found here 的文本,但希望文本隐藏在透明背景 div 而不是示例的白色背景后面。 CSS 这可能吗?原因是文本后面会有一个图像,我想淡入。
是的,您可以简单地通过在 @keyframes
上将 width
设置为 0 到 100%(如您问题中的示例)来显示文本的各个部分。
您可以通过一个小演示示例了解它的工作原理。点击零:
stripe.onclick = function() {
var sec = new Date().getSeconds() % 10;
stripe.classList.add('animate');
digit.classList.add('animate');
console.log();
};
#digit {
width: 20px;
overflow: hidden;
font: 32px "Courier New", monospace;
cursor: pointer;
transition: 2s linear width;
}
#stripe {
width: 20px;
transition: 2s linear width;
}
#stripe.animate {
width: 200px;
transition: 2s linear width;
}
#digit.animate {
width: 200px;
transition: 2s linear width;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Title</title>
<style>
</style>
</head>
<body>
<div id="digit"><span id="stripe">0123456789</span></div>
<script>
</script>
</body>
</html>
P.S.
JS 仅供测试。通过@keyframes 你不需要它们。