0

I want some images to not be displayed if the persons browser window is too small. Would I do this in CSS or Javasript, and if so, how?

entropy
  • 311
  • 1
  • 4
  • 15

3 Answers3

10
@media all and (max-width: 500px){ /* max screen size */
    #div { display: none; }
}
SeinopSys
  • 8,787
  • 10
  • 62
  • 110
2

You don't have to use JavaScript, you can simply do it with CSS @media queries

@media all and (max-width: 699px) { /* Change Width Here */
  div.class_name {
    display: none;
  }
}
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
2

You can do this in css using @media tags

   /*Show images for resolution greated than 1024*/
   @media only screen and (min-width: 1024px) {        
    img{ /*show all images*/
        display:block;
    }         
    }
    /*hide images for resolution lesser than 1024*/
    @media only screen and (max-width: 1024px) {        
    img{ /*hide all images*/
        display:none;
    }        
    }

In @media tags you can target specific device or all like screen alone, affect in print , mobile device etc or all

For doing this in javascript/jquery refer the below post,

How to detect in jquery if screen resolution changes?

Community
  • 1
  • 1
Gnanz
  • 1,833
  • 5
  • 24
  • 51