css - @media 不工作

标签 css media

我在这里阅读了很多“@media 不工作”的问题。不幸的是,他们中的大多数似乎都没有答案——或者答案并不能解决问题。祈祷这次不会发生!

这是我的代码:

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
@media screen and (min-width: 801px) {
.smallmobile {
 display: hidden !important;
 }
.mobileonly, .bigmobile {
 display: hidden !important;
 }
}
@media screen and (max-width: 800px) {
 font-family: Roboto, Noto, sans-serif;
.notformobile {
 display: hidden;
 }
}
@media screen and (min-width: 480px) and (max-width: 800px) {
 /* Target landscape smartphones, portrait tablets, narrow desktops */
 .smallmobile {
 display: hidden;
 }
}
@media screen and (max-width: 479px) {
 /* Target portrait smartphones */
 .bigmobile {
 display: hidden;
 }
}
</style>
</head>
<body>
Everyone can see this<br /><br />
There should be nothing below this line except on small mobiles:<br />
<span class="smallmobile"><a href="tel:+441234456789">Phone us on 01234 456789 to discuss your requirements</a></span><br /><br />
<div class="smallmobile"><a href="tel:+441234456789">Phone us on 01234 456789 to discuss your requirements</a></div><br /><br />
<a class="smallmobile" href="tel:+441234456789">Phone us on 01234 456789 to discuss your requirements</a>
</body>
</html>

我认为很明显什么是/不应该发生的。

为什么它不起作用?

[我已经在 Chrome 和 Firefox 上试过了。它对任何一个都不起作用。]

最佳答案

对于每个屏幕宽度,您都有 display: hidden,这意味着如果它有效,您将不会看到任何宽度的任何内容。此外,display: hidden 是无效的 CSS 规则。它应该是 display: none

要修复它制定第一条规则

@media screen and (min-width: 801px) {
.smallmobile {
 display: none !important;
 }
}

第二个

@media screen and (min-width: 480px) and (max-width: 800px) {
 /* Target landscape smartphones, portrait tablets, narrow desktops */
 .smallmobile {
   display: block;
 }
}

关于css - @media 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29039146/

相关文章:

html - 链接在移动响应式代码点火器中不起作用

CSS 悬停效果

php - Magento 1.9 - Media.phtml 内容未加载到我的可配置产品 View 页面中

linux - 构建开源媒体服务器

django - 如何通过 nginx 提供 django 媒体文件?

html - @media 部分样式未被应用;其他@media 部分工作

css - 使用 v-for 指令插入时 Vue 不应用样式

php - 使用php更改数据库中数据的字体颜色

javascript - 如何单击一次同时更改文本和图标

c - 如何使用gstreamer保存当前文件?