I have centered the element by the height of the screen using absolute positioning.
However, when the height of the screen is less than the element width, it is cutting the part of the element making its top unreachable. How can I add and remove styling if the height of the screen is less than the height of the element?
https://codepen.io/alena-chuyankova/pen/YzmWYKZ
.wrap {
position: absolute;
top: 50%;
transform: translate(0, -50%);
background-color: white;
gap: 1rem;
width: 45%;
box-shadow: rgba(50, 50, 93, 0.25) 0px 13px 27px -5px, rgba(0, 0, 0, 0.3) 0px 8px 16px -8px;
display: flex;
flex-direction: column;
padding: 4rem;
}
2
Answers
Using the CSS3
@Media
, you can achieve any responsive condition; for this case, I suggest using theaspect-ratio
This way you can create conditions for the CSS to be responsive to the situation.
For more options, I recommend reading MDN (since I feel like W3Schools are lacking examples)
Edit: I moved the comments
//
because they can’t be inside the@media
The strictly answer I can make to your question is this snippet below:
Try running the snippet, open Full Page then try resizing the display frame through the Dev Tools.
NOTE: The listener is only observing the height.
EDIT: I did some changes to the snippet:
1.1.
theConfiguration.classList
accepts an array with element classes to observe or a string like'class1,class2;class3 class4'
.