0

I just wrote a media query for phone displays and it's not applying. The code in question is below. For better context, my github page is here. What I'd like is for the food pics to stack and take up the entire width of the screen as seen in the first pic at the bottom.

@media only screen and (max-width: 480px) {
  .food {
    height: 265px;
    width: 400px;
    padding: 0rem;
    position: relative;
    top: 7rem;
  }
}

The media query actually displays somewhat properly when I resize my desktop browser (first pic), but does not work at all on my iPhone 6 (second pic) -- the images are flanked by sizable margins and don't fill the screen. I say "somewhat properly" because there is a large right margin for when the media query applies on the desktop browser -- you'll see it when you resize your browser when the media query takes effect. Not sure why that's happening either. I have a hunch it has to do with how I have my flexbox set up, but I'm not sure.

Here's what I've tried:

-Using the <meta name="viewport" content="width=device-width,initial-scale=1"> meta tag

-Setting the media query to portrait orientation.

Thanks for any help you can provide!

enter image description here

enter image description here

Johannes
  • 64,305
  • 18
  • 73
  • 130
  • Are you sure that the iPhone 6 has a `max-width` of `480px`? See this answer on SO to see the width's: https://stackoverflow.com/a/25759240/6773269 – Patrick Mlr Jan 08 '18 at 13:46
  • Are you linking to an external CSS file or is it all in the same file? Could copy your page into a JSFiddle or something so we can see? – Sam Johnson Jan 08 '18 at 13:53

3 Answers3

0

Try to remove only from your media query and write it like this instead:

@media screen and (max-width: 480px) {
}

Also max-width: 480px, does not match with the size of the iPhone 6 screen size. See the following specifications for the actual screen size:

(min-width : 375px) // or 213.4375em or 3in or 9cm
(max-width : 667px) // or 41.6875em
Mikkel Fennefoss
  • 857
  • 1
  • 9
  • 32
0

You are using fixed width and heigth for that image class on your Github page, which isn't good for that purpose (small screens).

In the CSS rule for .food, change width to 100%, height to auto (to keep the image proportions intact) and add box-sizing: border-box to include the padding into the 100% width. (Or set padding to 0 if you really want the images to span the whole width)

Johannes
  • 64,305
  • 18
  • 73
  • 130
-2

Here's some breakpoints you can use in your code for different devices & orientations:

/* Smartphones (portrait and landscape) ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}

/* Smartphones (landscape) ----------- */
@media only screen and (min-width : 321px) {
/* Styles */
}

/* Smartphones (portrait) ----------- */
@media only screen and (max-width : 320px) {
/* Styles */
}

/* iPads (portrait and landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
/* Styles */
}

/* iPads (landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
/* Styles */
}

/* iPads (portrait) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
/* Styles */
}
/**********
iPad 3
**********/
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}

@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
/* Desktops and laptops ----------- */
@media only screen  and (min-width : 1224px) {
/* Styles */
}

/* Large screens ----------- */
@media only screen  and (min-width : 1824px) {
/* Styles */
}

/* iPhone 4 ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}

@media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}

/* iPhone 5 ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

@media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

/* iPhone 6 ----------- */
@media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

@media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

/* iPhone 6+ ----------- */
@media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

@media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

/* Samsung Galaxy S3 ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

/* Samsung Galaxy S4 ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}

@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}

/* Samsung Galaxy S5 ----------- */
@media only screen and (min-device-width: 360px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}

@media only screen and (min-device-width: 360px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}
Bruno Sousa
  • 480
  • 3
  • 12