html - CSS 媒体最大和最小宽度
问题描述
我有 2 个div
标签,我只想根据屏幕尺寸显示其中一个,
但是对于特定的屏幕尺寸(在我的情况下为 699px),它们都显示了,我不明白为什么。
有谁知道为什么?
更具体地说,我不明白为什么第二个 div 显示在 699px 的屏幕上。
此外,如果我将屏幕尺寸更改max-width
为698px
698 像素,则不会显示第二个 div。
任何想法为什么?
万一这很重要,我的项目是使用 React v17 构建的
html:
<div class='first'>first</div>
<div class='second'>second</div>
CSS:
@media (min-width: 700px) {
.first {
display: none;
}
}
@media (max-width: 699px) {
.second{
display: none;
}
}
===================== 编辑
关于@Imran Rafique 的回答
解决方案
干得好
.first, .second {
width: 100%;
background-color: red;
height: 100vh;
}
@media (min-width: 700px) {
.first {
display: none;
}
}
@media (max-width: 699px) {
.second{
display: none;
}
}
<div class='first'><h1>first</h1></div>
<div class='second'><h1>Second</h1></div>
推荐阅读
- android - 在 viewModelScope 中抛出异常,但在它之外捕获它
- f# - 在 F# 中流式传输服务器发送的事件 (SSE)
- python - 如何使用 Celery 获取计划任务列表及其参数?
- python - 将 Excel 文件导出为 pdf,包括打印标题
- python - Plotly 地图未显示在 VS Code 中的 Jupyter Notebook 中
- django - Django 查询集 Postgres
- overlay - 带有 UpdateLayeredWindow 功能的 ImGui 覆盖
- backend - 我想在不使用元掩码的情况下连接合同
- javascript - HTML5 视频标签显示空白页,在 Safari、iPhone 和 iPad 中不起作用
- python - ImportError: cannot import name 'LayerNormalization' from 'tensorflow.python.keras.layers.normalization' ,在 colab 上出现此错误?