Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide div on mobile devices, using CSS

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.

like image 437
Christos Baziotis Avatar asked Jun 04 '13 16:06

Christos Baziotis


People also ask

How do I hide things in mobile view?

Once the browser/screen reaches 600pixels then #title_message will become hidden. EDIT: if you are using another CSS for mobile then just add the visibility: hidden; to #title_message . Hope this helps you! That fixed it.

How do you hide a division in CSS?

You can hide an element in CSS using the CSS properties display: none or visibility: hidden. display: none removes the entire element from the page and mat affect the layout of the page. visibility: hidden hides the element while keeping the space the same.

How to hide a Div on a mobile device?

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.

How to hide an element in a responsive layout using CSS?

Solutions with CSS ¶ To hide an element in a responsive layout, we need to use the CSS display property set to its "none" value along with the @media rule. The content of the second <p> element having a "hidden-mobile" class will be hidden on devices smaller than 767px.

How to hide elements on mobile devices using bootstrap 4?

In Bootstrap 3.4.1, we can use the "hidden-xs" class to hide an element on phones. So, in the next example, we demonstrate how a <strong> element will be hidden on extra small devices. In Bootstrap 4, the hidden-* (also visible-*) class does not exist any more.

How do I show and hide content on my website?

Learn how to use a few snippets of CSS to show and hide content on any website regardless of how the website was built. See how to use the built in Responsive Layout settings on any Beaver Builder module to show and hide content. Using a combination of CSS and a few Dynamik Website Builder settings you can easily show and hide content.


4 Answers

For some reason (unknown to me) this worked:

<div  class="mobile-hide">
<div class="fb-like-box" data-href="https://www.facebook.com/mypage" data-width="220" data-height="250" data-show-faces="true" data-stream="false" data-header="true"></div>
</div>
like image 120
Christos Baziotis Avatar answered Oct 13 '22 08:10

Christos Baziotis


Make sure your page defines a viewport meta tag.

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

For more information on this tag see: Understanding The Viewport Meta Tag.

like image 37
Dan Avatar answered Oct 13 '22 06:10

Dan


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

like image 6
Muddasir Abbas Avatar answered Oct 13 '22 06:10

Muddasir Abbas


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.

like image 1
Julian B Avatar answered Oct 13 '22 08:10

Julian B