首页 > 解决方案 > Adsense 广告有时不居中和/或出现在奇怪的地方

问题描述

这似乎是一个相对简单的问题,但我无法找到任何有效的答案。经常(但并非总是),当 Google 向我的网页投放广告时,它们会出现偏离中心或完全在父 div 之外。我知道这与广告在 div 中的绝对定位有关,我尝试过使用 CSS(包括在style属性下的 Google 广告代码中),但无济于事。

我没有使用自动广告,并将data-ad-format字段更改为“水平”(第一张图片)和“矩形”(第二张图片)。我还将该data-full-width-responsive字段更改为“假”。

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ad header -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9877834918277834"
     data-ad-slot="1366524238"
     data-ad-format="auto"
     data-full-width-responsive="false"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

包含广告的 div 的 CSS 如下:

.ad-slot {
  width: 100%;
  overflow: hidden; /* Otherwise be outside the div */
  text-align: center; /* Doesn't seem to do anything */
}

在此处输入图像描述

在此处输入图像描述

标签: csstwitter-bootstrapadsenseabsolute

解决方案


原来这是一个 iframe 样式问题。我正在使用一些 JS 并意外地最终设计了页面上的所有 iframe(包括广告)。


推荐阅读