1

我在 DIV 中有一个段落,当宽度 > 500 时我想完全隐藏它,当宽度 < 500 时显示它。我不确定这里有什么问题。

<head>
<style type="text/css">
#mobileshow    { display:none; }

@media screen and (max-width: 500px) {
#mobileshow   { display:block; }
}
</style>
</head>

<div id="mobileshow"><p>Click the images below to download.</p></div>
4

4 回答 4

7

显然我的格式是错误的。错误的地方有太多的空格或换行符。不确定是哪个。这是更新的代码:

<style type="text/css">
#mobileshow { 
display:none; 
}
@media screen and (max-width: 500px) {
#mobileshow { 
display:block; }
}
</style>

<div id="mobileshow"><p>Click the images below to download.</p></div>
于 2015-12-30T17:10:46.630 回答
2

做这个

#mobileshow    { display:block; }

@media screen and (min-width: 500px) {
    #mobileshow   { display:none; }
}
于 2015-12-30T16:53:41.763 回答
2

另一种方式

@media only screen and (min-width: 500px) {
#mobileshow  {
display: none !important;}
}
于 2017-08-09T09:13:09.590 回答
0

如果您在主元素中使用 display flex,请不要使用 display 块,因为它会破坏元素的样式,请使用display:flex

于 2021-04-07T02:44:50.650 回答