0

A picture = 1000 words so let me show you what I mean:

Example Image

Div 1 is the common parent which is the container, Divs 2 are the unique parents which are columns and Divs 3 are the 2 children that I want to align horizontally. Their size is dynamic and none of them have a fixed height, but if one of them is higher than the other I want both of them to be displayed with the same height.

I have used flexbox to align Divs 2 horizontally already and even if their size , here is how the HTML and CSS look for now:

HTML

<div id="div1">
  <div id="div2">Text div 2
    <div id="div3">Text div 3</div>
  </div>
  <div id="div">Text div 2
    <div id="div3">Text div 3</div>
  </div>
</div>

CSS

#div1 {
  display:flex;
  flex-direction: row;
}

#div2 {
  border: 1px dotted black;
  border-radius: 20px;
}

Could you help me to align Divs 3 horizontally and make them appear as same height please?

Thanks a lot!

Nisharg Shah
  • 16,638
  • 10
  • 62
  • 73
  • aligning *flex items* in adjacent flexboxes is not possible... see [here](https://stackoverflow.com/questions/55272962/alignment-of-content-vertically-in-adjacent-flexbox-containers/55291645#55291645) for a similar issue... – kukkuz Apr 22 '19 at 08:28

2 Answers2

0

you can use align-items:stretch on parent to achieve this

#div1 {

  display:inline-flex;
  border: 2px solid red;
}


#div3 {
  width: 200px;
  border: 2px solid lime;
}

#div3-2 {
  width: 200px;
  border: 2px solid lime;
}


#div,
#div2 {
  border: 2px solid blue;
  margin: 10px;
  padding: 10px;
  display: flex;
}
<div id="div1">

  <div id="div2">
    <div id="div3">Text div 3Text div 3Text div 3Text div 3Text div 3Text div 3Text div 3Text div 3Text div 3Text xt di</div>
  </div>

  <div id="div">
    <div id="div3-2">Text div 3 Text di</div>
  </div>

</div>
ashish singh
  • 6,526
  • 2
  • 15
  • 35
-1

please try this code:

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>test template</title>
    <!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

        <style>
          #div1 {

            display:inline-flex;
            flex-direction: row;
            align-items: stretch;
            border: 2px solid red;
          }


          #div3 {
            width: 100px; 
            border: 2px solid lime;
          }

          #div3-2 {
            width: 100px;
            border: 2px solid lime;
          }


          #div,
          #div2 {
            border: 2px solid blue;
            margin: 10px;
            padding: 10px;
          }

        </style>


</head>

<body>

  <div id="div1">

    <div id="div2">Text div 2
      <div id="div3">Text div 3</div>
    </div>

    <div id="div">Text div 2
      <div id="div3-2">Text div 3 lorem ipsum afda adsfa sdfa fdsa fdafdsa fda sdfa fd</div>
    </div>

  </div>
</body>

</html>
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57