欢迎您来到,李雷博客 | PHP博客        登录  |  注册

谷歌AdSense广告匹配不到显示空白时用CSS隐藏或替换为图片美化

更新:2023-02-07 18:27:12
人气:319
来源:本站原创
A+

谷歌AdSense广告经常会出现匹配不到的时候,出现此种情况后会直接占位成空白,页面效果上看非常不好看,所以通过官方的介绍可以用CSS隐藏或替换成占位图片的链接。

Google 官方推荐使用 CSS,在广告代码中属性有使用 data-ad-status 来指示广告展示位置是否已填充,可以定位到应用 CSS 来隐藏元素。

ins.adsbygoogle[data-ad-status="unfilled"] {
    display: none !important;
}

方案一:增加一个图片链接,如果广告未填充显示出来就用指定的图片显示占位

<div style="width:920px; height:auto; clear:both; margin:5px auto; text-align: center">
   <ins class="adsbygoogle"
		 style="display:inline-block;width:880px;height:110px"
		 data-ad-client="ca-pub-746454xxxxx"
		 data-ad-slot="5151889170">
         <a href="https://www.mdaima.com" target="_blank" class="zhanwei_a"><img src="/images/ad/ad_2.gif" style="width:880px; height:125px;"></a>
    </ins>
	<script>
		 (adsbygoogle = window.adsbygoogle || []).push({});
	</script>
</div>

<style>
ins.adsbygoogle .zhanwei_a {
    display: none !important;
}
ins.adsbygoogle[data-ad-status="unfilled"] .zhanwei_a {
    display: block !important;
}
</style>

方案二:如果广告未显示出来就直接隐藏

<div class="art_ad_w2" style="width:920px; height:auto; clear:both; margin:10px auto; text-align: center;">
	<!-- 文章底部 -->
	<div class="left_column">
                        <ins class="adsbygoogle w_2"
		 style="display:inline-block;width:880px;height:110px"
		 data-ad-client="ca-pub-746454xxxxx"
		 data-ad-slot="5151889170"></ins>
	<script>
		 (adsbygoogle = window.adsbygoogle || []).push({});
	</script>
    </div>
</div>
<style>
ins.w_2[data-ad-status="unfilled"] {
    display: none !important;
}
</style>
推荐的文章
# 发表我的评论
  /     /  
# 最近评论
暂时还没有评论,要不要说点什么?
  Ads by Google
  联系博主
Hello,本博客系统采用PHP和MySql开发,程序开发完全是因为个人爱好,是自己纯手写PHP源代码,未采用任何PHP框架!
QQ:858353007   微信号:lileihot123
网站地图
会员服务
关于我们
QQ:858353007
 
广告服务
加我微信
移动端访问
 
 
Copyright © 2014- 2024 www.mdaima.com All Rights Reserved.
李雷博客,专注PHP经验、PHP教程及PHP源代码开源下载分享的PHP博客!   ICP备案号:京ICP备10202169号-4