欢迎访问WDPHP素材源码!今天是2024年04月28日 星期日,中午好!吃了吗?
您好,游客 [ 马上登录 | 注册帐号 | 微信登录 | QQ登录]
当前位置:首页 > 教程 > 前端开发 > 

谷歌AdSense广告匹配不到显示空白时用CSS隐藏或替换为图片美化
栏目分类:前端开发    发布日期:2023-11-11    浏览次数:284次     收藏

谷歌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.19jp.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>
源码 模板 特效 素材 资源 教程 站长