我有这个代码。
<div style="clear: both; display: flex;margin-bottom: 2%;">
<div id="divnumber1" style="clear: both;width: 55%;text-align: left;float: left;padding-top: 3%;padding-left: 15%;">
<span style="word-wrap: break-word;text-align: left;">Where would you say you shop most often?</span>
</div>
<div id="divnumber2" style="font-size: 36px;text-align: left;float: left;margin-left: 10%;">
<div onclick="disclosure(this);" style="clear: both;">›</div>
</div>
</div>
我想要divnumber1
和divnumber2
相同的尺寸。所以我使用flex
属性来实现这一点。我希望div
内部divnumber2
居中。但事情是,它做不到。我尝试了很多方法。当span
的文字变大时,就像这样。
我如何将文本置于div
divnumber2
内部
答案 0 :(得分:0)
你说你在2个div上使用了display:flex
。所以使用align-self:center;
justify-content:center;
到内部div。
见下文
让我知道是否有帮助
#divnumber1 {
background:red;
display:flex;
}
#divnumber2 {
background:grey;
display:flex;
}
#divnumber2 div {
align-self:center;
justify-content:center;
}
&#13;
<div style="clear: both; display: flex;margin-bottom: 2%;">
<div id="divnumber1" style="clear: both;width: 55%;text-align: left;float: left;padding-top: 3%;padding-left: 15%;">
<span style="word-wrap: break-word;text-align: left;">Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</span>
</div>
<div id="divnumber2" style="font-size: 36px;text-align: left;float: left;margin-left: 10%;">
<div onclick="disclosure(this);" style="clear: both;">›</div>
</div>
</div>
&#13;