css - 如何将div中的文本居中

标签 css html center

这是我的 HTML:

<div class="fourcol" align="center" ;="" style="float:;">
<h2 class="center" style="text-align: center;">More Mentors Announced Soon</h2>

文本本身是居中对齐的,但我希望它在页面内水平居中。我该怎么做?

这是我一直在使用的 CSS

.fourcol, {
    position: relative;
    float: left;
    margin-right: 2.762430939%;
    margin-bottom: 20px;
    margin-top: 20px; 
}


h2.center {
    width: 50%;
    margin: 0 auto;

最佳答案

尝试这个。将类 fourcol 更改为更多

.more {
    float: left;
    width: 100%;
}
<div align="center" class="more">
<h2 style="text-align: center;" class="center">More Mentors Announced Soon</h2>
</div>

关于css - 如何将div中的文本居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21057229/

相关文章:

html - 可以用 HTML 表格绘制的东西

html - 将div的高度动态设置为页面剩余空间

html - 如何将一个 div 左对齐,另一个 div 居中对齐?

css - 在 css 中居中

javascript - 如何在用户单击时将一个 SVG 换成另一个 SVG

html - Bootstrap : Vertical navbar that responsively switches to horizontal?

html - 在响应中交换不同列中的 div(列子)

javascript - 不使用模板引擎的 CSRF 保护 - Javascript 和 Flask

html - Bootstrap 缩略图 - 中心内容(img + 标题),标题 float :left

html - Leaflet + D3 - Safari 上没有鼠标悬停