Trying to modify the css of an element if the screen resolution is less than 960px
my code isn't working, not seeing any errors in firebug.
<script type="text/javascript">
jQuery(window).resize(function() {
if (jQuery(window).width() < 960) {
jQuery(".snow").css('display', 'none');
}
});
</script>
The @media CSS at-rule can be used to apply part of a style sheet based on the result of one or more media queries. With it, you specify a media query and a block of CSS to apply to the document if and only if the media query matches the device on which the content is being used.
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.
Using CSS, you can set the background-size property for the image to fit the screen (viewport). The background-size property has a value of cover . It instructs browsers to automatically scale the width and height of a responsive background image to be the same or bigger than the viewport.
Use window. innerWidth and window. innerHeight to get the current screen size of a page.
You can do this entirely with CSS using the @media
command.
@media (max-width:960px) { css... } //nothing with screen size bigger than 960px
@media (min-width:960px) { css... } //nothing with screen size smaller than 960px
See here
Jason Whitted makes a good point, this is CSS 3 only, so it won't work with older browsers (it should work with all modern browsers though). See here for compatibility. Your main problems will be IE 8 and less.
Edit - device selection
@media screen { .nomobile { display: block; } } //desktops/laptops
@media handheld { .nomobile { display: none; } } //mobile devices
Or you could assume mobile devices will have a smaller width, and go on that.
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