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.
Make sure your page defines a viewport meta tag.
For more information on this tag see: Understanding The Viewport Meta Tag.
Okay I had this problem a while back, and for some odd reason it only worked when i put my media query rules at the end of the css. Don't know why that is, maybe a bug of some sort, but give that a try and let us know if that works.
For some reason (unknown to me) this worked:
Source: https://blog.hubspot.com/marketing/site-content-only-mobile-viewers-can-see-ht
This code should work, You could also do a mobile redirect, or you can use JavaScript to detect the device (android or iPhone) though I would recommend I combination of the two and take note of screen sizes.
Other links
https://coderwall.com/p/i817wa/one-line-function-to-detect-mobile-devices-with-javascript
What is the best way to detect a mobile device in jQuery?