2

I wrote a simple HTML program for experimental purposes:
Here is the code:

<!DOCTYPE html>
<html>
<head>
<style>
body {
    background-color: green;
}

@media screen and (device-height: 375px) and (device-width: 667px) {
    body {
        background-color: blue;
    }
}
</style>
</head>
<body>

<p>Media queries are simple filters that can be applied to CSS styles. They make it easy to change styles based on the characteristics of the device rendering the content, including the display type, width, height, orientation and even resolution.</p>

</body>
</html>

But ut doesn't change color when it is tried in iPhone 6. What is wrong with the code? Is logical expression correct?

1
  • device-width and device-height will calculate exact width and height. So use min-height and min-width instead of device-width and device-height. Commented Nov 3, 2014 at 11:00

3 Answers 3

1

this works for me on the iphone 6:

@media only screen and (min-device-width: 374px) and (max-device-width: 376px)

this works on the iphone 6+:

@media only screen and (min-device-width: 413px) and (max-device-width: 415px)
Sign up to request clarification or add additional context in comments.

4 Comments

So I should use min-device-width and max-device-width? Check first answer
Great,this worked... But how do you know the values?
trial and error^^ pls accept the answer if it works:-)
Accepted the answer :)
1

This works in a browser and hopefully on your IPhone too:

(Max-width and min-width instead of device-height and device-width)

<!DOCTYPE html>
<html>
<head>
<style>
body {
    background-color: green;
}

@media screen and (max-height: 375px) and (max-width: 667px) {
    body {
        background-color: blue;
    }
}
</style>
</head>
<body>

<p>Media queries are simple filters that can be applied to CSS styles. They make it easy to change styles based on the characteristics of the device rendering the content, including the display type, width, height, orientation and even resolution.</p>

</body>
</html>

Comments

1

Use max-device-width and min-device-height.

@media all and (min-device-width: XXXpx) and (max-device-width: XXXpx)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.