【发布时间】:2016-01-28 00:53:12
【问题描述】:
我正在尝试编写媒体查询以使网站在 iPad 中看起来合适。
我将所有设备 css 文件都保存为 mobile.css。在 mobile.css 下面是我如何进行一些更改。
下面是 CSS 代码 sn-p。
@media screen and (max-width: 1024px) {
.tobeaddedtobutton {
background-color: transparent;
width: 100%;
height: 35px;
border-radius: 0px;
background-image: url("../assets/tablet/btn-border-yellow.png");
background-repeat: no-repeat;
text-align: left;
font-family: Signika;
color: white;
border: none;
font-size: 13px;
}
.tobeaddedtobutton-1 {
background-color: transparent;
width: 100%;
height: 35px;
border-radius: 0px;
background-image: url("../assets/tablet/btn-border-orange.png");
background-repeat: no-repeat;
text-align: left;
font-family: Signika;
color: white;
border: none;
font-size: 13px;
}
}
当设备是 iPad 时,我只是尝试向按钮添加不同的边框图像。但是当我在此媒体查询下更改路径时,浏览器正在为所有设备读取此代码,这是不正确的。
我做得对吗?
请提出建议。
【问题讨论】:
-
你的问题有点不清楚。 “但是当我在此媒体查询下更改路径时,浏览器正在为所有设备读取此代码,这是不正确的”是什么意思。 ?
-
您的媒体查询会将视口小于 1024 像素的任何设备设置为使用这些样式。无论如何,您不应该只针对 iPad,您应该在网站布局变得混乱时更改样式
-
据我所知(不多),您无法仅使用 css 检测用户代理或用户平台!有什么理由,你不想避免使用 JS 吗?您还可以使用 js 将 UA 信息存储在 html 属性中,然后使用 css 根据这些属性应用样式!
-
您在媒体查询中缺少右括号
-
我必须将
background-image应用于仅适用于 iPad 的几个按钮。对于所有其他设备,图像会有所不同,并且很少有其他小的排列,因此使用这种方式
标签: html css twitter-bootstrap ipad media-queries