css - 媒体查询不适用于移动设备
问题描述
我有一个类,媒体查询如下:
@media only screen and (max-width: 374px) {
width: 62px;
}
@media only screen and (max-height: 413px) and (min-width: 375px) {
width: 75px;
}
@media only screen and (min-width: 414px) {
width: 85px;
}
中间媒体查询似乎不起作用。注意:媒体查询适用于移动设备
解决方案
你不需要添加max-height
,你需要的max-width
,有标准尺寸的手机在这里查看这篇文章以及它是如何工作的,所以你需要添加的只是将你的类推送到查询中,例如:
@media only screen and (max-width: 374px) {
.class{
//style here will display on sizes from 0px to 374px
}
}
@media only screen and (min-width: 375px) {
.class{
//style here will display start display from 375px
}
}
@media only screen and (min-width: 414px) {
.class{
//style here will display start sizes from 414px
}
}
检查这也包含几乎媒体查询大小
完整示例:
HTML:
<!doctype html>
<meta name="viewport" content="width=device-width"/>
<body>
<h1>Media Queries Examples</h1>
<p>Increase or decrease the size of your window to see the background color change</p>
</body>
CSS:
p{
font-family: arial,san-serif;
font-size: 13px;
font-color: black;
}
h1{
font-size:30px;
}
@media screen and (min-width:761px){
body{
background-color:white;
}
h1{
color:red;
}
}
@media screen and (max-width:760px){
body{ background-color: #333;
}
h1{
color:red;
}
p{
color: white;
}
}
@media screen and (max-width:480px){
body{ background-color: #807f83;
}
h1{
color:white;
}
p{
color: white;
}
}
@media screen and (max-width:360px){
body{ background-color: #0096d6;
}
h1{
color:white;
font-size:25px;
}
p{
color: white;
}
}
推荐阅读
- postgresql - 我该如何写这个错误:关系“照片”不存在并且“用户”的相同错误不会发生
- reactjs - 组件在重新渲染时失去功能
- php - 将每个 url 重定向到索引时得到 404
- javascript - 我有一个小问题要混淆,当我单击按钮添加新表时,它不能在下面添加
- processing - Neovim 如何从 Powershell 调用命令?
- javascript - 为什么我们需要在 rxjs observable 中实现 unsubscribe?
- javascript - backdraft 组件是否对插入它的 dom 元素有任何可见性?
- python - XPath 文本和节点按实际顺序排列
- python - Python Pandas 仅对列进行分组
- javascript - 在没有外部包的 Javascript 中将带时区的时间戳字符串转换为 UTC