我有三個不同的div標籤(不在對方內)與代碼,所以它有一個單詞向左,中或右,但中心是非常關閉居中。下面是HTML代碼:我想中心在我的頁面中間的文本HTML
.desc {
float: right;
color: skyblue;
}
.desc1 {
float: left;
color: skyblue;
}
.desc2 {
text-align: center;
color: skyblue;
}
<div class="desc1">
<h2>What we are here to do!</h2>
<p>Example</p>
</div>
<div class="desc2">
<h2>What we have completed</h2>
<p>Recent work (can include pictures)</p>
</div>
<div class="desc">
<h2>Company Description</h2>
<p>EXAMPLE!</p>
</div>
已經問過的問題:https://stackoverflow.com/questions/42187838/how-to-vertically-cente r-a-div-on-page/45110782#45110782 – Super
如果你想讓它工作,你需要改變順序。要浮動到右側的元素必須是第一個或第二個。如果您將其作爲最後一個,那麼它不會以任何方式影響元素放置之前的位置。無論如何,你或許不應該這樣使用浮動功能;查看flexbox。 – CBroe
你可以顯示包含這個div的父標籤的代碼嗎?這可能是因爲父標籤的寬度不夠這3個div? – 2017-07-28 13:15:06