这是我的 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/