Reputation: 234
So i tried to create a mobile first display but when i used media query with min-width(which is supposed to say : when device width is at least or equal to the specified width then apply the specified styles) but whole display for mobile also broke and it also got applied with the min-width styles.
@media only screen and (min-width: 700px){
body{
font-size: 1.8rem;
}
#hamburger{
display: none;
}
nav ul{
display: flex;
justify-content: space-around;
}
}
In this first image i removed media query and this is what i get
In this second image i added media query which didn't work well
Here's full code on codepen : https://codepen.io/Harsh_X/pen/mdVEORY
Upvotes: 0
Views: 647
Reputation: 20954
Don't forget to add the viewport meta tag. Without it devices with high pixel densities, like the iPhone 6 and up, will be rendered differently without accounting for the characteristics of the screen. Those devices tell you that they have a width of 375
pixels, but the actual resolution of the screen is the double of that: 750
pixels. That is because the device has a pixel ratio of 2
or higher. So all the numbers are doubled (or more) in reality.
So your media query sees that the device has 750
pixels in width, but they are rendered in 375
pixels, which is confusing, and therefor will trigger the media query at 700
pixels.
The meta tag here below corrects these values. A more detailed explanation can be found on this article on MDN, which explains why a single pixel is really not a single pixel.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Upvotes: 4