I'm creating a responsive website. I use something like this for hiding some elements for mobile display:
@media (max-width: 599px) {
.hidden-mob{
display: none !important;
}
}
// and then add "hidden-mobile" class for arbitrary elements
Now I need to check some elements from the height aspect. I tried this: @media (max-height: x)
but I don't know why it does not work. Also it should be noted that I need to a OR
, I want this condition:
If current-height <= x or current-width <= y Then hide element
How can I implement the above condition using CSS ?
You can hide an element in CSS using the CSS properties display: none or visibility: hidden . display: none removes the entire element from the page and mat affect the layout of the page. visibility: hidden hides the element while keeping the space the same.
To hide an element in a responsive layout, we need to use the CSS display property set to its "none" value along with the @media rule. The content of the second <p> element having a "hidden-mobile" class will be hidden on devices smaller than 767px.
you can wrap another div around the outside of it, and probably tell it a specific height to occupy. that way your inner div can show and hide and fadeOut, etc, and the outer div will hold down the real-estate on the page.
Use ,
to implement the OR
condition.
@media (max-width: 599px), (max-height: 700px) {
.hidden-mob {
display: none;
}
}
<div class="hidden-mob">Hidden below 599px width or when height is below 700px</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