如何修改Google Adsense广告位的宽高

向右看齐 2023-07-07 14:56 10阅读 0赞

在自己的博客网站放了 Google Adsense 的广告,但是样式和网站整体的风格都不太搭。

1、希望设置正方形的广告位的宽度

查了下文档可以修改 节点的 style 参数,如我希望

  • 宽度设置位 div 宽度的 80%
  • 降低广告位的透明度
  • 在 div 中居中

修改代码如下:

  1. <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
  2. <ins class="adsbygoogle"
  3. style="display:block;width:90%;margin:0 auto;opacity:80%;"
  4. data-ad-client="ca-pub-6582448306453788"
  5. data-ad-slot="9580931533"
  6. data-ad-format="auto"
  7. data-full-width-responsive="true"></ins>
  8. <script>
  9. (adsbygoogle = window.adsbygoogle || []).push({});
  10. </script>

2、移动端,打开页面,广告的宽度占据整个移动设备的屏幕宽度。希望设置广告不是占据整个屏幕的宽度,而是在 div 内,保持页面风格一致。

这个需要修改 节点的 data-full-width-responsive=”false”,不让广告单元完全占据用户所用移动设备的屏幕宽度。

修改后完整代码如下:

  1. <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
  2. <ins class="adsbygoogle"
  3. style="display:block;width:90%;margin:0 auto;opacity:80%;"
  4. data-ad-client="ca-pub-6582448306453788"
  5. data-ad-slot="9580931533"
  6. data-ad-format="auto"
  7. data-full-width-responsive="false"></ins>
  8. <script>
  9. (adsbygoogle = window.adsbygoogle || []).push({});
  10. </script>

PC端效果:

format_png

移动端效果:

format_png 1

PS:

Google Adsense 文档 URL(需墙)


【Java面试题与答案】整理推荐

  • 基础与语法
  • 集合
  • 网络编程
  • 并发编程
  • Web
  • 安全
  • 设计模式
  • 框架
  • 算法与数据结构
  • 异常
  • 文件解析与生成
  • Linux
  • MySQL
  • Oracle
  • Redis
  • Dubbo

发表评论

表情:
评论列表 (有 0 条评论,10人围观)

还没有评论,来说两句吧...

相关阅读