将外部div的高度继承到内部div

时间:2016-07-29 10:12:19

标签: css html5 css3

我有这个代码。

<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>

我想要divnumber1divnumber2相同的尺寸。所以我使用flex属性来实现这一点。我希望div内部divnumber2居中。但事情是,它做不到。我尝试了很多方法。当span的文字变大时,就像这样。

the final look

我如何将文本置于div

中的divnumber2内部

1 个答案:

答案 0 :(得分:0)

你说你在2个div上使用了display:flex。所以使用align-self:center; justify-content:center;到内部div。

见下文

让我知道是否有帮助

&#13;
&#13;
#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;
&#13;
&#13;