Hide div on mobile devices, using CSS

2020-02-05 05:34发布

I want to hide a div containing the facebook likebox widget from mobile devices. I tried this but it doesn't work.

div code:

<div id="facebook" class="fb-like-box mobile-hide" data-href="https://www.facebook.com/mypage" data-width="220" data-height="250" data-show-faces="true" data-stream="false" data-header="true"></div>

css code:

@media screen and (min-width: 0px) and (max-width: 720px) {
  #facebook { display: none; }
  .mobile-hide{ display: none; }
}

What am i doing wrong? It does not work using the id or the class reference.

10条回答
Animai°情兽
2楼-- · 2020-02-05 06:11

Try these it works for me.

Example 1:

@media only screen and (max-width: 479px) {
   .mobile-hide{ display: block !important; }
}

Example 2:

@media only screen and (max-width: 479px) {
   .mobile-hide{ display: none !important; }
}

description link

查看更多
冷血范
3楼-- · 2020-02-05 06:18

I personally think your "display" parameter is the wrong one, try using visibility instead. I tested it and it worked for me.

This one should work for you:

@media only screen and (min-device-width: 0px) and (max-device-width: 720px) {div#facebook {visibility:hidden;}}

I think you can even forget about the use of a class.

查看更多
别忘想泡老子
4楼-- · 2020-02-05 06:19

Just delete the "and (min-device-width: 0px)"

查看更多
forever°为你锁心
5楼-- · 2020-02-05 06:20

Try this.

 .mobile-hide{ visibility: hidden; }

edit: sorry, meant to put visibility.

查看更多
叛逆
6楼-- · 2020-02-05 06:20

If you are working on a fluid grid layout, DW already created the 3 media queries for you. To hide a DIV on phone only apply:

#div{ display:none; } The trick is,that you have to add this line to tablet

#div{ display:block; //or inline or anything, how you wish to display it }

It works for me, hope it's useful.

查看更多
Lonely孤独者°
7楼-- · 2020-02-05 06:22

Why not add the evil !important to your display: none?

查看更多
登录 后发表回答