rasikag rasikag - 4 months ago 12
CSS Question

Inherit outer div's height to inner div

I have a this code.

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


I wanna same size of the
divnumber1
and
divnumber2
. So I used
flex
attribute to achieve that. The I wanna center the inner
div
in
divnumber2
. But thing is, it can't do. I tried lot of ways. When the
span
's text get bigger it is like this.

the final look

How I center the text in inner
div
in
divnumber2
??

Answer

you said you used display:flex on the 2 divs. so use align-self:center; justify-content:center; to the inner div .

see below

let me know if it helps

#divnumber1 {
  background:red;
  display:flex;
}
#divnumber2 {
  background:grey;
  display:flex;
}
#divnumber2 div {
  align-self:center;
  justify-content:center;
}
<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>

Comments