【问题标题】:Google ad cannot find a responsive size in non-fixed width divGoogle 广告在非固定宽度的 div 中找不到响应式尺寸
【发布时间】:2015-11-24 20:29:08
【问题描述】:

我在让 AdSense 广告出现在非固定宽度的 div 中时遇到问题。基本上,我有两个并排放置的 div,我希望 Google 广告出现在第二个中,它没有设置固定宽度。查看我的示例代码:

<div style="width:1000px">

<div style="float:left; width:200px">
test
</div>

<div style="float:right; overflow:hidden">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
 style="display:block"
 data-ad-client="ca-pub-1234"
 data-ad-slot="5678"
 data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>

</div>

Google 拒绝投放广告,但我收到以下错误:“找不到宽度=0px 的容器的响应尺寸”

任何想法如何解决这个问题?谢谢!

【问题讨论】:

  • 你搜索过吗?同一个问题有很多问题。其中许多问题已经以一种或另一种方式解决了。
  • 是的,我已经搜索过了——事实上我有两个相邻的 div,这使得这个比看起来更具体。我已经尝试设置超时或使用 onload 来调用广告,但这并没有成功。

标签: html responsive-design adsense


【解决方案1】:

我最终使用了这个解决方案:

Cannot find a responsive size for a container of width=0px and data-ad-format=auto adsense

...我认为这只是一种解决方法,但似乎向 Google 提供实际宽度是(唯一)这样做的方法。

来自来源 (Google):如果您将自适应广告代码放置在没有明确设置宽度的父容器中,例如,在浮动元素中,那么我们的广告代码将无法计算自适应广告单元所需的尺寸。在这种情况下,您需要修改代码并使用 CSS 媒体查询来设置父容器的大小。

PS:要使广告正确居中,如果您使用的是链接到解决方案,请将“margin:auto”放在 .banner 类中。

【讨论】:

    猜你喜欢
    • 2016-01-19
    • 1970-01-01
    • 2016-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 2021-07-27
    相关资源
    最近更新 更多