I am struggling to prevent a relative positioned div text content from overflowing outside of the bounds.
Markup:
<div class="parent">
<div class="details">
<div class="detail1">
lotsoftext lotsoftext lotsoftext lotsoftext lotsoftext lotsoftext lotsoftext lotsoftext lotsoftext lotsoftext lotsoftext lotsoftext
</div>
<div class="detail2">
lotsmoretext lotsmoretext lotsmoretext lotsmoretext lotsmoretext lotsmoretext
lotsmoretext lotsmoretext lotsmoretext lotsmoretext lotsmoretext lotsmoretext
</div>
</div>
</div>
CSS:
.parent {
margin: 5px;
max-height: 100px;
max-width: 400px;
background: pink;
}
.details {
width: 100%;
text-align: center;
font-size: 14pt;
display: grid;
grid-template-rows: 1fr 1fr;
}
.detail1 {
grid-row: 1;
overflow-y: hidden;
}
.detail2 {
grid-row: 2;
overflow-y: hidden;
}
Check this JFiddle to show the problem
3
Answers
You should add overflow: hidden; or remove max-height from parent.
you can change max-height unit from px to vh it will work for you
The only thing that comes to mind using height and overflow on exact same elements as you is
line clamp