Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide div element when screen size is smaller than a specific size

I have a div element that I want to hide when the width of the browser is less than or equal to 1026px. Is this possible to do with the css: @media only screen and (min-width: 1140px) {} If it isn't possible with css, Is there any alternative?

Extra info: When the div element is hidden, I don't want a blank white gap. I'd like the page to flow as it would if I deleted the div element entirely from the code.

The div I am hiding is <div id="fadeshow1"></div>.

HTML5 Doctype.

I used javascript to place a gallery into that div.


I want it to look like this when it is bigger than 1026px width: http://i.stack.imgur.com/REBPi.png


I want it to look like this when it is less than 1026px width: http://i.stack.imgur.com/XdiL4.png

like image 925
Brett Merrifield Avatar asked Nov 20 '12 15:11

Brett Merrifield


People also ask

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?

We hide the divs by adding a CSS class called hidden to the outer div called . text_container . This will trigger CSS to hide the inner div.


1 Answers

You can do this with CSS:

@media only screen and (max-width: 1026px) {     #fadeshow1 {         display: none;     } } 

We're using max-width, because we want to make an exception to the CSS, when a screen is smaller than the 1026px. min-width would make the CSS rule count for all screens of 1026px width and larger.

Something to keep in mind is that @media queries are not supported on IE8 and lower.

like image 82
Cerbrus Avatar answered Oct 10 '22 08:10

Cerbrus