![](/img/trans.png)
[英]Do I need to use another property other than “text-align” to center my DIV within a DIV?
[英]How do I center align a div within another div
我試圖居中對齊位於另一個div內的div。 我想垂直居中位於“計划容器”內部的“選項” div
提前致謝。
.plan-container { width: 960px; height: auto; margin-top: 62px; overflow: hidden; background-color: red; } .options { float: left; width: 151px; height: 100px; background-color: green; } .plan { float: left; width: 220px; height: 600px; margin-left: 23px; background-color: purple; } .plan:last-child { float: right; } .plan-featured{ width: 300px; height: 600px; background-color: purple; }
<div class="plan-container"> <div class="options">Options</div> <div class="plan">Box one</div> <div class="plan plan-featured">Box two</div> <div class="plan">Box three</div> </div>
Vucko的答案是正確的。 我想添加評論,但由於我的聲譽還不夠,我將其發布為答案。
您可以在需要居中的內部div
上使用vertical-align
屬性。 此屬性僅適用於具有display:inline-block
或display:table
元素。 請參閱此處的實際規格。
重復Vucko的回答:
.options {
display: inline-block;
vertical-align: middle;
}
試試吧-
.plan-container {
display: flex;
flex-wrap: wrap; /* optional. only if you want the items to wrap */
justify-content: center; /* for horizontal alignment */
align-items: center; /* for vertical alignment */
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.