this article mainly introduces the production method of css3 to create text streamer gradient effects. it has certain reference value. interested friends can refer to it. i hope it will be helpful to you!
first the renderings
the following begins up code
html part
html> <meta> <title>title</title> <p> </p><h4>日暮苍山远,天寒白屋贫。柴门闻犬吠,风雪夜归人。</h4>
css part
<style> .masked h4{ display: block; width: 600px; height: 100px; /*渐变背景*/ background-image: -webkit-linear-gradient(left, #3498db, #f47920 10%, #d71345 20%, #f7acbc 30%, #ffd400 40%, #3498db 50%, #f47920 60%, #d71345 70%, #f7acbc 80%, #ffd400 90%, #3498db); color: transparent; /*文字填充色为透明*/ -webkit-text-fill-color: transparent; -webkit-background-clip: text; /*背景剪裁为文字,只将文字显示为背景*/ background-size: 200% 100%; /*背景图片向水平方向扩大一倍,这样background-position才有移动与变化的空间*/ /* 动画 */ animation: masked-animation 4s infinite linear; } @keyframes masked-animation { 0% { background-position: 0 0; /*background-position 属性设置背景图像的起始位置。*/ } 100% { background-position: -100% 0; } } </style>
actually, this is a very simple example. i won’t go into details about the role of attributes here, because the documentation can be found. i will mainly talk about the ideas here.
1. the linear-gradient attribute adds a linear gradient background color to the text span>
2. transparent set the text to transparent
at this time, you will find that the text has disappeared, and only the background color is left on the screen, but we know that the text has not disappeared, and the transparent elements still exist in the document (still occupying space).
3. background-clip cuts the background into text, and the screen becomes like this .
this is easy to understand. as a metaphor, you wear an invisibility cloak and become invisible. at this time, someone poured a bucket of paint on you, and you appeared
(i i don't know if this is the right way to describe it. i have a vague feeling that there will be a better explanation for this. i hope everyone can give me some advice.)
4. animation setting animation. we achieve this effect by changing the background color position, so we need to enlarge the background-size first so that the background-position has room to change.
the above steps are simple: add a gradient background to the text and set the text to be transparent , then use the text as the screen background, and achieve this effect by controlling the position change of the background color.
[related tutorial recommendations]
1. css video tutorial
2. css online manual
3. bootstrap tutorial