Subj.
I have two divs (left and right). And I want to make left div something like main one, and force right div to have the same height as a left one, even if it will have more content (and do overflow: hidden
). I will appreciate if there is a way to make it with css
and html
without js
.
Here is a little snippet, how my markup is looking:
.parent {
display: flex;
flex-direction: row;
align-items: stretch;
}
.children-1 {
width: 66.6%;
background: green;
}
.children-2 {
width: 33.4%;
background: yellow;
}
<div class="parent">
<div class="children-1">
<p>My content</p>
</div>
<div class="children-2">
<p>a lot of content<p>
<p>a lot of content</p>
</div>
</div>
Apply a fixed height to the container and use overflow-y: hidden;
on the second child DIV:
.parent {
display: flex;
flex-direction: row;
align-items: stretch;
height: 200px;
}
.children-1 {
width: 66.6%;
background: green;
}
.children-2 {
width: 33.4%;
background: yellow;
overflow-y: hidden;
}
<div class="parent">
<div class="children-1">
<p>My content</p>
</div>
<div class="children-2">
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
</div>
</div>
Here's a second version without fixed height, but the HTML structure is changed: There is only one child (the right one), and the contents which were in the first child are now in the parent. It uses absolute positioning for that child element and hides the overflow of the child element - see the actual settings below:
html,
body {
margin: 0;
}
.parent {
position: relative;
padding: 1em;
background: green;
overflow-y: hidden;
}
.children-2 {
width: 33.4%;
position: absolute;
right: 0;
top: 0;
background: yellow;
}
<div class="parent">
<p>My content</p>
<p>My content</p>
<div class="children-2">
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
<p>a lot of content</p>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With