Overflowing container with equally tall children
P粉207969787
P粉207969787 2024-03-22 13:42:51
0
2
683

I searched the available questions but didn't find a solution.

I'm trying to set the height of all elements of a horizontal overflow container to be equal to the height of the longest element.

body {
    
}
section{
    width: 300px;
    background: lightblue;
    overflow: auto;
    white-space: nowrap;
}
div{
    display: inline-block ;
    max-width: 150px;
    background: lightgreen;
    margin: 5px;
    white-space: normal;
    
    /* not working */
    height: 100%;
}
<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
    </head>
    <body>
        <section>
            <div>
                hi there how are you push just IV by Rd hi TX cu
            </div>
            <div>
                hi there how are you push just IV by Rd hi TX cu jdi HD so of fr edg of Dr edg KB hi
            </div>
            <div>
                hi there how are you push just IV by Rd hi TX cu
            </div>
        </section>
    </body>
</html>

As you can see, the second div is the longest. The other div should be equal to the second div. Also, I don't need a fixed height.

P粉207969787
P粉207969787

reply all(2)
P粉790819727

You can use Flex layout.

section{
  width: 300px;
  background: lightblue;
  overflow: auto;
  white-space: nowrap;
  display: flex;
  align-items: center;
}
div{
  display: inline-block ;
  max-width: 150px;
  background: lightgreen;
  margin: 5px;
  white-space: normal;
  height: 100%;
}
P粉403821740

Set min-width on divs so that its parent flex cannot be wrapped.

section {
  display: flex; /* new */
  flex-wrap: nowrap; /* new */
  width: 300px;
  background: lightblue;
  overflow: auto;
}

div {
  min-width: 150px; /* new */
  background: lightgreen;
  margin: 5px;
}
hi there how are you push just IV by Rd hi TX cu
hi there how are you push just IV by Rd hi TX cu jdi HD so of fr edg of Dr edg KB hi
hi there how are you push just IV by Rd hi TX cu
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template