简体   繁体   English

CSS文字宽度从左到右

[英]CSS text width left to right

I'm trying to fade in text from left to right similar to answer found here , but want the text to be hidden behind a transparent background div instead of the example's white background. 我正在尝试从左向右淡入文本,类似于此处找到的答案 ,但希望将文本隐藏在透明背景div(而不是示例的白色背景)后面。 Is this possible with CSS? CSS有可能吗? Reason being there will be a image behind the text that I'd like to fade in. 原因是我想淡入的文字后面会有图像。

Yes, you can simple make it by setup the width from 0 to 100% on @keyframes (as in example in your question) to show the parts of the text. 是的,您可以通过在@keyframes width设置为0到100%(例如在您的问题中的示例中)以显示文本的部分,来简单地进行设置。

Small demo-example for you to show is how it work. 您可以通过一个小的演示示例来了解其工作原理。 Click on Zero: 单击零:

 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> 

PS PS

JS only for test. JS仅用于测试。 By @keyframes you do not need them. 通过@keyframes,您不需要它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM