html - CSS 根据屏幕大小更改内容
问题描述
我曾经从我想使用 CSS 构建的 Flash 应用程序中看到一个效果 - 当用户将浏览器窗口的大小调整到超出最小可视区域(例如小于 500x800 像素)时,将内容替换为一条消息,指出可视屏幕大小太小
我尝试了能够隐藏原始显示内容的@media 指令,但我无法用消息替换它
@media screen and (max-width:900px), screen and (max-height:500px) {
.wrapper { display: none !important; }
.notice { display: block; visibility: visible; }
}
.notice {
display: none;
visibility: hidden;
}
编辑:添加 HTML 代码
<body>
<div class="wrapper">
<header class="header">My header</header>
<aside class="sidebar">Sidebar</aside>
<article class="content">
<h1>2 column, header and footer</h1>
<p>This example uses line-based positioning, to position the header
and footer, stretching them across the grid.</p>
</article>
<footer class="footer">My footer</footer>
</div>
<div class="notice">notice</div>
</body>
当我将浏览器窗口的大小调整到超出给定大小但无法显示通知 div 时,CSS 中的上述代码能够隐藏 div 包装器。当屏幕尺寸达到预期尺寸时,应隐藏 div 通知
在这一点上,我不想考虑任何 CSS 框架。主要是因为我是 CSS 新手,而且我也认为这有点矫枉过正
PS 我只能使用 IE11 - 不要问我为什么
解决方案
你需要把那个@media
css放在css下面.notice
。
<div class="wrapper">
i am wrapper
</div>
<div class="notice">
i am notice
</div>
.notice {
display: none;
visibility: hidden;
}
@media screen and (max-width:900px), screen and (max-height:500px) {
.wrapper { display: none !important; }
.notice { display: block; visibility: visible; }
}
推荐阅读
- android - Android APK 不包含 MainActivity 类
- mysql - mysql json_contains 可以不区分大小写吗?
- r - 在 R 中创建显示多个行业的异常回报发展的 geom_table 时出错
- json - 从 T-SQL 查询中将键值对输出为 JSON
- django - 如何访问 DetailView 和 CreateView 的外键连接的两个模型?
- r - 如何使用 data.table 对 fast_strptime 进行矢量化以实现快速日期时间
- c# - 没有这样的主机是已知的-> System.Net.Http.HttpRequestException:
- c# - C# FTPS FtpWebRequest 设置被动模式以使用端口范围
- server - 使用 ansible 在远程机器上挂载点附件
- mongodb - 找出在 MongoDB 中创建数据库/集合的用户