css - CSS - 使居中的文本看起来像打字机
问题描述
我正在尝试制作一个居中的单行文本,使其字母一个接一个地出现,并在其右侧有一个光标。我在下面使用此代码,但它有一些我无法解决的问题:
1)文字虽然我使用text-align: center
但一开始没有居中但在左边然后去中心
2)文本最初不是出现在一行上,而是出现在多行上。
.header {
background-color: black;
padding: 2%;
text-align: center;
}
.test {
color: white;
overflow: hidden;
font-size:25px;
border-right:2px solid #7CDD26;
animation-delay: 2s;
animation-duration: 12s;
animation-fill-mode: both;
animation-name: spin1;
}
@-webkit-keyframes spin1 {
0% {width:0px;border-right:0px;}
1% {width:0px;border-right:2px solid #7CDD26;}
99% {width:400px;border-right:2px solid #7CDD26;}
}
<div class="header">
<div class="test">This is a test.</div>
</div>
解决方案
对于 (a) - 由于您将width
属性设置为块级元素 ( div
),因此您需要边距以auto
使元素居中。text-align
属性使容器内的文本居中,而不是容器本身。
至于 (b) - 你已经设置了overflow
属性,但是由于你没有设置height
,初始值为auto
.
所以你的代码可以调整为:
.header {
background-color: black;
padding: 2%;
text-align: center;
}
.test {
color: white;
overflow: hidden;
font-size:25px;
border-right:2px solid #7CDD26;
animation-delay: 2s;
animation-duration: 12s;
animation-fill-mode: both;
animation-name: spin1;
margin: auto;
height: 25px;
}
@-webkit-keyframes spin1 {
from {width:0px;border-right:0px;}
to {width:400px;border-right:2px solid #7CDD26;}
}
<div class="header">
<div class="test">This is a test.</div>
</div>
希望有帮助!
推荐阅读
- c# - 尝试根据表行的最高 ID 更新特定 SQL Server 表列时出错
- python - 在python中使用liblas和laspy读取las文件的问题
- html - Z-index 没有堆叠
- python - 如何在没有导入库的情况下在 python 文件中获取函数定义?
- java - 从android studio中的按钮单击访问url
- javascript - 如何使用 ArrayBuffer/ArrayBufferView 通过 WebSocket 发送字符串和整数的 Javascript 数组?
- android - 更改 TextInputLayout 提示字体
- regex - 使用正则表达式查找包含在特殊字符中的字符串
- python - 如何从另一个经过训练的模型中提取模型
- haskell - Jake Wheat 的“Intro to Parsing with Parsec in Haskell”过时了吗?