谷歌AdSense广告匹配不到显示空白时用CSS隐藏或替换为图片美化
谷歌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>
相关内容
这些是最新的
热门排行
- THINKPHP5+GatewayWorker+Workerman 开发在线客服系统
- 在手机浏览器网页中点击链接跳转到微信界面的方法
- 尊云网站目录系统 ThinkPHP5网站分类目录程序 v2.2.221011
- CentOS 7安装shadowsock(一键安装脚本)
- AdminTemplate 基于LayUI 2.4.5实现的网站后台管理模板
- 用NW.js(node-webkit)开发多平台的桌面客户端
- PHP生成随机昵称/用户名
- THINKPHP5网站分类目录程序 尊云网站目录系统
- 织梦(DEDECMS)微信支付接口 微信插件
- 基于LayUI开发的 网站后台管理模板 BeginnerAdmin
- 响应式后台网站模板 - AMA.ADMIN
- layuiAdmin后台管理模板 Iframe版
- LayUI 1.0.9 升级 至 LayUI 2.1.4 方法
- 简洁清爽的会员中心模板
- jQuery幸运大转盘抽奖活动代码