【发布时间】:2017-02-28 02:13:31
【问题描述】:
我是 Web 开发的新手,我正在尝试弄清楚媒体查询是如何工作的。我正在尝试为移动设备显示一个图像,为桌面显示一个更大的图像。我已经最大限度地简化了项目,以隔离问题,并且还制作了不同的背景颜色以更好地区分。这是我的文件:
HTML:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Website</title>
<link rel="stylesheet" media="screen and (max-width:500px)" type="text/css" href="phoneStyle.css">
<link rel="stylesheet" media="screen and (min-width:501px)" type="text/css" href="desktopStyle.css">
</head>
<body>
<div id="wrap">
<img id="phone" src="phoneImg.jpg" height="100%" />
<img id="desktop" src="desktopImg.jpg" height="100%" />
</div>
</body>
</html>
CSS:
phoneStyle.css
#desktop {
display: none;
}
body {
background-color: red;
margin: 0px;
}
desktopStyle.css
#phone {
display: none;
}
body {
background-color: black;
margin: 0px;
}
我只在两台设备上都获得了带有黑色背景的桌面图像。我正在使用 MAMP 在本地服务器上进行测试。任何帮助表示赞赏。
【问题讨论】:
标签: html css mobile media-queries mobile-website