Google广告在非固定宽度div中找不到自适应大小

时间:2015-08-30 19:50:56

标签: html responsive-design adsense

我在将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拒绝投放广告,但是我收到以下错误:&#34;无法找到宽度为= 0px&#34的容器的响应大小;

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

1 个答案:

答案 0 :(得分:0)

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

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

...我认为这只是一种解决方法,但看起来像喂Google实际宽度是(唯一)这样做的方式。

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

PS:要正确居中,如果您正在使用链接解决方案,请将&#34; margin:auto&#34;在.banner课程中。

相关问题