display:none
on the parent div
does not stop ad requests from that ad unit:
<div style="display:none">
<ins class="adsbygoogle adslot_1" ... ></ins>
</div>
This goes against the AdSense policy regarding hiding ads: "Hiding ad units at anytime (e.g., display:none
), unless you're implementing a responsive ad unit."
To actually prevent ad requests, we should apply display:none
to the AdSense ins
tag itself:
<style type="text/css">
.adslot_1 { display: inline-block; width: 320px; height: 50px; }
@media (max-width: 400px) { .adslot_1 { display: none; } }
@media (min-width: 500px) { .adslot_1 { width: 468px; height: 60px; } }
@media (min-width: 800px) { .adslot_1 { width: 728px; height: 90px; } }
</style>
<ins class="adsbygoogle adslot_1"
data-ad-client="ca-pub-1234"
data-ad-slot="5678"></ins>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
This is an advanced feature called "Hiding an ad unit". In the scenario where the viewport is under 401px, the above code will insert a
<!--No ad requested because of display:none on the adsbygoogle tag-->
comment within the
ins
tag instead of displaying the advertisement.
If you want to demonstrate how to "move" AdSense ads, my JSFiddle example titled "How to 'move' AdSense ads" might be what you're looking for - "I wanted to show another AdSense Ad which is in another DiV with display:block
". (Move the vertical border to see the ads "moving".)