【发布时间】:2019-08-19 03:08:35
【问题描述】:
为什么以下代码中的文本不在中心? (标题和标语行)。
应该是
body {
margin: 0;
padding: 0;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #000;
}
p {
position: relative;
font-family: sans-serif;
text-transform: uppercase;
font-size: 2em;
letter-spacing: 4px;
overflow: hidden;
background: linear-gradient(90deg, #000, #000fe6, #000);
background-repeat: no-repeat;
background-size: 80%;
animation: animate 3.75s linear infinite;
-webkit-background-clip: text;
-webkit-text-fill-color: rgba(45, 45, 45, .05);
}
@keyframes animate {
0% {
background-position: -500%;
}
100% {
background-position: 500%;
}
}
<body>
<div>
<p>Title</p>
<p>Tag Line</p>
</div>
</body>
为什么上面代码中的文本不在中心? (标题和标语行)
应该是
【问题讨论】:
-
为什么不在
p规则中添加text-align: center;? -
将 text-align:center 添加到 div 标签或你的 body 标签
-
扩展上述 cmets - 这是因为您的 flex 仅将 div 对齐到中心并使 div 与其内容一样大 - divs 内容左对齐