【发布时间】:2014-12-30 14:31:05
【问题描述】:
您好,我遇到了一个小的媒体查询问题。我正在处理的网站上的徽标在移动设备上时不会调整大小。所以我试图添加下面的代码,但它没有做任何事情。有没有办法设置它以便它也可以在移动设备上运行?
链接:http://eyeandretina.com.au/
.header_left a img
{
float: left;
margin-right: 20px;
width:612px;
}
media {
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
.header_left a img {
width:100px;
}
/* Smartphones (landscape) ----------- */
@media only screen
and (min-width : 321px) {
/* Styles */ .header_left a img {
width:100px;
}
}
/* Smartphones (portrait) ----------- */
@media only screen
and (max-width : 320px) {
/* Styles */ .header_left a img {
width:100px;
}
}
/* iPads (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */ .header_left a img {
width:100%;
}
}
/* iPads (landscape) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */ .header_left a img {
width:100%;
}
}
/* iPads (portrait) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */ .header_left a img {
width:100px;
}
}
/* Desktops and laptops ----------- */
@media only screen
and (min-width : 1224px) {
/* Styles */ .header_left a img {
width:100%;
}
}
/* Large screens ----------- */
@media only screen
and (min-width : 1824px) {
/* Styles */ .header_left a img {
width:100px;
}
}
/* iPhone 4 ----------- */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
.header_left a img {
width:100px;
}
}
【问题讨论】:
-
它似乎可以在 Firefox 和 Chrome 中使用。
-
Chrome 允许您通过检查元素 devtool 中的“设备模式”在不同设备中查看您的页面。在检查元素部分,您可以在元素选项卡旁边看到一个“移动”图标。单击它时,将打开设备模式,您可以在左上角选择设备。我在 iPhone 6 plus 设备模式下使用此功能检查了您的页面,并且徽标正在根据您的媒体查询调整为 100 像素宽度。