I’m looking for something a bit strange in pure CSS (if it’s possible) …
I have a modal without height but with a max-height and I have a content which should be of a certain height but it should be 100% of the height of the parent max!
I don’t know if you really get me so here’s a sample of what i’m trying to do :
#modal {
height: auto;
width: auto;
max-height: calc(100vh - 50px);
max-width: calc(100vw - 50px);
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: 1px solid red;
padding: 5px;
}
#modal-content {
width: 700px;
height: 700px;
max-height: 100%; /* this should be 100% of the parent but don't work */
border: 1px solid blue;
padding: 5px;
}
<div id="modal">
<div id="modal-content"></div>
</div>
If you know any way of making it I’ll appreciate it !
Thanks for your help !
2
Answers
Use flexbox and you can rely on the shrink effect
you can use the min() feature for the modal-content height.
If you set the height to min(700px, 100%), it will be at most 700px, but will be smaller than 100% of the parent’s height.
Keep in mind, that you have a 5px padding and a 1px border. (12px in total bottom/top).
This is the correct code to achive your goal: