[英]CSS Media Queries Not Working on Mobile
我會保持簡潔。使用Zurb Foundation 5建立一個網站。 媒體查詢無效。 代碼如下:
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>...</title>
<link rel="stylesheet" href="css/foundation.css" />
<link rel="stylesheet" href="css/styles.css" />
<script src="js/vendor/modernizr.js"></script>
</head>
相關的CSS設置如下:
#examplediv {
style:background-image;
}
@media only screen and (max-width: 40em) {
#examplediv {
style:different-background-image;
}
}
按照此頁面在媒體查詢中使用em
有任何想法嗎?? 在這瘋狂。 謝謝!
使用此元標記和媒體查詢,
<header>
<meta name="viewport" content="width=device-width">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
</header>
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-width : 320px)
and (max-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-width : 768px)
and (max-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
@media only screen
and (min-width : 768px)
and (max-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
@media only screen
and (min-width : 768px)
and (max-width : 1024px)
and (orientation : portrait) {
/* 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 (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
將媒體查詢添加到Foundation.css文件中時,它將無法正常工作。 您應該為媒體查詢創建一個單獨的CSS文件並覆蓋它。 創建一個文件並編寫如下代碼。 我寫過改變顏色。
@media only screen and (max-width: 40em) {
body {
background-color: yellow;
}
}
@media only screen and (min-width: 41em) {
body {
background-color: red;
}
}
只需將背景顏色的標簽更改為圖像即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.