Naijalog
  • Home
  • News
    • Top Stories
    • World News
  • Trending
  • Entertainment
    • Cinemas
    • Interviews
    • Events
    • Music
    • Videos
  • Sports
    • Football
      • Premiership
      • NPL
    • WORLD CUP 2018
  • Lifestyle
    • Nutrition
    • Health
    • Sex and Relationships
  • Quizzes
No Result
View All Result
  • Home
  • News
    • Top Stories
    • World News
  • Trending
  • Entertainment
    • Cinemas
    • Interviews
    • Events
    • Music
    • Videos
  • Sports
    • Football
      • Premiership
      • NPL
    • WORLD CUP 2018
  • Lifestyle
    • Nutrition
    • Health
    • Sex and Relationships
  • Quizzes
No Result
View All Result
Naijalog
No Result
View All Result

How To Hide/Display Different Adsense Ads In Desktop & Mobile using CSS

naijalog by naijalog
October 2, 2016
in Technology
Reading Time: 2 mins read
0
How To Hide/Display Different Adsense Ads In Desktop & Mobile using CSS
0
SHARES
Share on FacebookShare on TwitterShare on Whatsapp

google-adsense

Google AdSense has introduced Responsive Ads long back to make sure the Ad gets displayed depending on the screen resolution. For example, when you choose responsive ad, a 728×90 leaderboard ad will be displayed in the desktop version and a smaller 468×60 banner to viewers on a tablet.  But what if you completely want to hide the ad?

Below is a way using CSS class to hide Google AdSense on Mobile, as well as Desktop

RelatedArticles

Kolawole Ajeyemi Backs Toyin Abraham After Funke Akindele Premiere Snub

“I Won’t Greet Her Again” — Toyin Abraham Responds After Premiere Snub

Hide AdSense Ad on mobile using CSS:

Create a CSS class and use the Media CSS query, considering the width of the screen into account. Here we have created a class “hideonmobile”, which will not display the contents if the screen size is less than 480px.
Add the same class to your AdSense code too. Which will make the code look like this:
<style>
@media (max-width: 480px) {
.hideonmobile {
display: none !important;
}
}
</style>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

<ins class="adsbygoogle hideonmobile"
 style="display:inline-block;width:336px;height:280px"
 data-ad-client="ca-pub-7525498198"
 data-ad-slot="6727986789"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Note: Replace the publisher id  (data-ad-client) and adslot id (data-ad-slot) with your own AdSense IDs. 

Hide AdSense Ad on desktop or tablet using CSS:

This is almost similar to the above case. There is only one change that you have to make in order to make it work. Replace the “max-width” in the CSS with “min-width”. This will not display the ad if the screen size if more than 480px.
Here’s the code:
<style>
@media (min-width: 480px) {
.hidedst {
display: none !important;
}
}
</style>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

<ins class="adsbygoogle hidedst"
 style="display:inline-block;width:336px;height:280px"
 data-ad-client="ca-pub-7525498198"
 data-ad-slot="6727986789"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
ShareTweetSend

Leave a ReplyCancel reply

  • Contact us
  • Advertise with us

© 2022 Naijalog

No Result
View All Result
  • Entertainment
  • Top Stories
  • Trending
  • Sports
  • Lifestyle

© 2022 Naijalog

 

Loading Comments...