我试图将我的标题居中,所以我使用了 white-space: nowrap; 所以它没有堆叠并且出现在一行中,但现在它不会居中。这样就有了标题的 CSS 代码,它的外观很好,唯一的问题是,它不是居中显示,而是从中心开始,并且一直向右移动。就像,它不是“与探索者见面”,而是“与探索者见面”
我的代码片段是:
.section-title {
font-size: 4rem;
font-weight: 300;
color: black;
margin-bottom: 10px;
text-transform: uppercase;
letter-spacing: 0.2rem;
clear: both;
display: inline-block;
overflow: hidden;
white-space: nowrap;
justify-content: center;
}
<div class="about-top"> <h1 class="section-title">Meet the <span>SEE</span>kers</h1> <p>We are a team of young entrepreneurs, who decided it was time to modernize the way we search the web. A diverse group of unexpected talents came together to make SEE-Tool available to every web user.</p> </div>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我不确定为什么你的代码中有
justify-content: center,因为它在那里没有做任何事情。您也不需要inline-block因为span标签不是块元素。您可以删除
display属性并添加text-align: center,这样它将居中您的h1标记。.section-title { font-size: 4rem; font-weight: 300; color: black; margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.2rem; text-align: center; }