[英]How do i center the animation of my paragraph?
i can't seem to start the animation from the center, it goes from left to right我似乎无法从中心启动 animation,它从左到右
Since my paragraph is centered, i want it to start from the center only.由于我的段落居中,我希望它只从中心开始。
any suggestions?有什么建议么? Thank you.
谢谢你。
.p1 { display: flex; margin-top: 5%; justify-content: center; animation: ltr 3s steps(38); overflow: hidden; white-space: nowrap; border-right: 4px solid black; width: 38ch; } /* Animation */ @keyframes ltr { 0% { width: 0ch; } 100% { width: 22ch; } }
<strong><p class="p1">Simply... Privacy focused. Nontracable</p></strong>
Best strategy is to wrap the text element in a div
and give it a width equal to 100vw
.最好的策略是将文本元素包装在一个
div
中,并给它一个等于100vw
的宽度。 Next, add display: flex
and justify-content: center
to center the text element.接下来,添加
display: flex
和justify-content: center
以使文本元素居中。 Finally, make sure to give your text element an initial width of 0
and make the animation forwards
so that the text remains after the animation is over.最后,确保将文本元素的初始宽度设置为
0
,并使 animation forwards
移动,以便在 animation 结束后保留文本。
Here's the updated code:这是更新的代码:
div { display: flex; margin-top: 5%; justify-content: center; width: 100vw; }.p1{ animation: ltr 3s steps(38) forwards; overflow: hidden; white-space: nowrap; border-right: 4px solid black; width: 0; } /* Animation */ @keyframes ltr { 0% { width: 0ch; } 100%{ width: 22ch; } }
<,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width. initial-scale=1.0"> <title>Document</title> </head> <body> <div> <strong><p class="p1">Simply... Privacy focused. Nontracable</p></strong> </div> </body> </html>
You can make the p
an inline-block (instead of using flex
), wrap it in a div
and apply text-align: center
to that wrapper div:您可以使
p
成为内联块(而不是使用flex
),将其包装在div
中并将text-align: center
应用于该包装器 div:
.p1 { display: inline-block; margin-top: 5%; animation: ltr 3s steps(38); overflow: hidden; white-space: nowrap; border-right: 4px solid black; width: 38ch; } div.wrap { text-align: center; } /* Animation */ @keyframes ltr { 0% { width: 0ch; } 100% { width: 22ch; } }
<div class="wrap"> <p class="p1"><strong>Simply... Privacy focused. Nontracable</strong></p> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.