@Media最小宽度和最大宽度

我有这个@media设置:

<head>

<meta name="viewport" content="width=device-width, user-scalable=no" />

</head>

@media screen and (min-width: 769px) {

/* STYLES HERE */

}

@media screen and (min-device-width: 481px) and (max-device-width: 768px) {

/* STYLES HERE */

}

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

/* STYLES HERE */

}

通过此设置,它可以在iPhone上运行,但不能在浏览器中运行。

是因为我已经device在meta中,也许已经在max-width:480px

回答:

我发现最好的方法是为较旧的浏览器编写默认CSS,因为较旧的浏览器包括5.5、6、7和8。无法读取@media。当我使用@media时,我会这样使用:

<style type="text/css">

/* default styles here for older browsers.

I tend to go for a 600px - 960px width max but using percentages

*/

@media only screen and (min-width: 960px) {

/* styles for browsers larger than 960px; */

}

@media only screen and (min-width: 1440px) {

/* styles for browsers larger than 1440px; */

}

@media only screen and (min-width: 2000px) {

/* for sumo sized (mac) screens */

}

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

/* styles for mobile browsers smaller than 480px; (iPhone) */

}

@media only screen and (device-width: 768px) {

/* default iPad screens */

}

/* different techniques for iPad screening */

@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {

/* For portrait layouts only */

}

@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) {

/* For landscape layouts only */

}

</style>

但是,您可以使用@media进行任何操作,这只是为所有浏览器构建样式时最适合我的示例。

也!如果您正在寻找可印刷性,可以使用@media print{}

以上是 @Media最小宽度和最大宽度 的全部内容, 来源链接: utcz.com/qa/435407.html

回到顶部