CSS 移动设备的媒体查询不工作
CSS Media Queries For Mobile Devices Not Working
我正在使用媒体查询来提高我的网站的响应速度。但是,媒体查询在我的 PC 上运行得很好 (Chrome),但是在移动设备上查看时(iPad 和 iPhone)媒体查询似乎没有生效。我的头部有视口标签,但我猜我还遗漏了其他东西....
CSS
@media (min-width:320px) {
/* smartphones, iPhone, portrait 480x320 phones */
#mainText {
color: pink;
}
}
@media (min-width:481px) {
/* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */
#mainText {
color: blue;
}
}
@media (min-width:641px) {
/* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */
#mainText {
color: red;
}
}
@media (min-width:961px) {
/* tablet, landscape iPad, lo-res laptops ands desktops */
#mainText {
color: yellow;
}
}
@media (min-width:1025px) {
/* big landscape tablets, laptops, and desktops */
#mainText {
color: green;
}
}
@media (min-width:1281px) {
/* hi-res laptops and desktops */
#mainText {
color: purple;
}
}
HTML
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<div id="mainText">
<h1>Text</h1>
<h2>Text</h2>
</div>
您的 css
中似乎有一个过滤器
filter: brightness(1%);
现在因为您没有为 webkit 添加任何供应商前缀,chrome 只是决定忽略它。您可以删除此规则或将以下内容添加到您的 css.
-webkit-filter: brightness(1%);
filter: brightness(1%);
干杯,编码愉快!
由于您的查询可能会覆盖自身,请尝试类似的操作
为您的查询指定最小和最大宽度,它们始终比前一个查询小/大 1 像素
@media (max-width:320px) {
/* smartphones, iPhone, portrait 480x320 phones */
#mainText {
color: pink;
}
}
@media (min-width:321px) and (max-width:481px) {
/* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */
#mainText {
color: blue;
}
}
@media (min-width:482px) and (max-width:641px) {
/* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */
#mainText {
color: red;
}
}
@media (min-width:642px) and (max-width:1024px) {
/* tablet, landscape iPad, lo-res laptops ands desktops */
#mainText {
color: yellow;
}
}
@media (min-width:1025px) and (max-width:1280px){
/* big landscape tablets, laptops, and desktops */
#mainText {
color: green;
}
}
@media (min-width:1281px) {
/* hi-res laptops and desktops */
#mainText {
color: purple;
}
}
我正在使用媒体查询来提高我的网站的响应速度。但是,媒体查询在我的 PC 上运行得很好 (Chrome),但是在移动设备上查看时(iPad 和 iPhone)媒体查询似乎没有生效。我的头部有视口标签,但我猜我还遗漏了其他东西....
CSS
@media (min-width:320px) {
/* smartphones, iPhone, portrait 480x320 phones */
#mainText {
color: pink;
}
}
@media (min-width:481px) {
/* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */
#mainText {
color: blue;
}
}
@media (min-width:641px) {
/* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */
#mainText {
color: red;
}
}
@media (min-width:961px) {
/* tablet, landscape iPad, lo-res laptops ands desktops */
#mainText {
color: yellow;
}
}
@media (min-width:1025px) {
/* big landscape tablets, laptops, and desktops */
#mainText {
color: green;
}
}
@media (min-width:1281px) {
/* hi-res laptops and desktops */
#mainText {
color: purple;
}
}
HTML
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<div id="mainText">
<h1>Text</h1>
<h2>Text</h2>
</div>
您的 css
中似乎有一个过滤器filter: brightness(1%);
现在因为您没有为 webkit 添加任何供应商前缀,chrome 只是决定忽略它。您可以删除此规则或将以下内容添加到您的 css.
-webkit-filter: brightness(1%);
filter: brightness(1%);
干杯,编码愉快!
由于您的查询可能会覆盖自身,请尝试类似的操作 为您的查询指定最小和最大宽度,它们始终比前一个查询小/大 1 像素
@media (max-width:320px) {
/* smartphones, iPhone, portrait 480x320 phones */
#mainText {
color: pink;
}
}
@media (min-width:321px) and (max-width:481px) {
/* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */
#mainText {
color: blue;
}
}
@media (min-width:482px) and (max-width:641px) {
/* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */
#mainText {
color: red;
}
}
@media (min-width:642px) and (max-width:1024px) {
/* tablet, landscape iPad, lo-res laptops ands desktops */
#mainText {
color: yellow;
}
}
@media (min-width:1025px) and (max-width:1280px){
/* big landscape tablets, laptops, and desktops */
#mainText {
color: green;
}
}
@media (min-width:1281px) {
/* hi-res laptops and desktops */
#mainText {
color: purple;
}
}