[英]Issue with text filling, CSS Animation
這是一個 CSS 和 HTML animation,簡單的文字填充。
出於某種原因,當有空格或添加破折號時,文本會跳轉?
下面你可以看到 output:
我在下面添加了代碼!
.comingsoon-loading { font-family: 'Poppins', sans-serif; margin: 0; padding: 0; box-sizing: border-box; display: flex; justify-content: center; align-items: center; min-height: 100vh; }.comingsoon-loading h1 { position: absolute; font-size: 20vh; color: #ffcc00; -webkit-text-stroke: 2px black; text-transform: uppercase; }.comingsoon-loading h1::before { content: attr(data-text); position: absolute; top: 0; left: 0; width: 0; height: 100%; color: black; -webkit-text-stroke: 0px black; border-right: 4px solid black; overflow: hidden; animation: animate 6s linear infinite; } /* animation to fill text */ @keyframes animate { 0%,10%,100% { width: 0; } 50%,70% { width: 100%; } }
<div class="comingsoon-loading"> <h1 data-text="COMING-SOON">COMING-SOON</h1> </div>
您正在為一個緩慢出現的文本字符串設置動畫,但不考慮任何繼承字符串屬性,例如換行符。 在您的 animation 期間,第一個單詞:“COMING”,隨着寬度的增加正常出現,但是一旦出現連字符,HTML 就會認為您已經插入了一個斷點並試圖將“SOON”換成一個新行。
這可以通過添加white-space: nowrap;
到您的::before
部分,以防止它在 animation 播放時損壞。
HTML
<div class="comingsoon-loading">
<h1 data-text="COMING-SOON">COMING-SOON</h1>
</div>
CSS
.comingsoon-loading {
font-family: 'Poppins', sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: blue;
}
.comingsoon-loading h1 {
position: absolute;
font-size: 20vh;
color: #ffcc00;
-webkit-text-stroke: 2px black;
text-transform: uppercase;
}
.comingsoon-loading h1::before {
content: attr(data-text);
position: absolute;
top: 0;
left: 0;
width: 0;
height: 100%;
color: black;
-webkit-text-stroke: 0px black;
border-right: 2px solid black;
overflow: hidden;
animation: animate 5s linear infinite;
white-space: nowrap;
}
/* animation to fill text */
@keyframes animate {
0%,
10%,
100% {
width: 0;
}
50%,
70% {
width: 100%;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.