[英]css media max and min width
I have 2 div
tags, which I want to show only one of them depending on the screen size,我有 2 个div
标签,我想根据屏幕大小只显示其中一个,
but for a specific screen size (in my case 699px) both of them are shown and I can't understand why.但是对于特定的屏幕尺寸(在我的情况下为 699px),它们都显示了,我不明白为什么。
Anyone know why?有谁知道为什么?
More specific, I don't understand why the second div is shown on screen size of 699px.更具体地说,我不明白为什么第二个 div 显示在 699px 的屏幕尺寸上。
Further more, if I change the max-width
to 698px
the second div is not shown for screen size of 698px.此外,如果我将max-width
更改为698px
,第二个 div 不会显示为 698px 的屏幕大小。
Any ideas why?任何想法为什么?
In case it matters, my project is build with React v17万一重要,我的项目是用 React v17 构建的
html: html:
<div class='first'>first</div>
<div class='second'>second</div>
css: css:
@media (min-width: 700px) {
.first {
display: none;
}
}
@media (max-width: 699px) {
.second{
display: none;
}
}
Regarding the answer of @Imran Rafique关于@Imran Rafique 的回答
Here you go干得好
.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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.