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 scr
You simply need to use a media query in CSS to accomplish this.
@media (max-width: 1026px) {
#fadeshow1 { display: none; }
}
Unfortunately some browsers do not support @media
(looking at you IE8 and below). In those cases, you have a few options, but the most common is Respond.js which is a lightweight polyfill for min/max-width CSS3 Media Queries.
<!--[if lt IE 9]>
<script src="respond.min.js"></script>
<![endif]-->
This will allow your responsive design to function in those old versions of IE.
*reference
if you are using bootstrap u can just use the hidden-sm ( lg or md or xs) depending on what u want. u can then go into the css file and specify the percentages u want it to show on. in the sample below it will be hiding on large screens, medium ones and extra small ones but show on small screens by taking half of the screen.
<div class="col-sm-12 hidden-lg hidden-md hidden-xs">what ever you want</div>
This should help:
if(screen.width<1026){//get the screen width
//get element form document
elem.style.display == 'none'//toggle visibility
}
768 px should be enough as well
@media only screen and (min-width: 1140px)
should do his job, show us your css file
The easiest approach I know of is using onresize() func:
window.onresize = function(event) {
...
}
Here is a fiddle for it
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.