Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide div for specific height or width using CSS [duplicate]

Tags:

html

css

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 ?

like image 657
Shafizadeh Avatar asked Sep 09 '15 16:09

Shafizadeh


People also ask

How do you hide a division in 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.

How do I hide elements based on screen size?

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.

How do I hide a div but keep the space?

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.


1 Answers

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>
like image 154
m4n0 Avatar answered Oct 01 '22 06:10

m4n0