【问题标题】:Responsive Adsense ad unit won't display at 320x50 px自适应 Adsense 广告单元不会以 320x50 像素显示
【发布时间】:2016-01-08 01:51:23
【问题描述】:

我有一个响应式 Adsense 广告单元,我想将它用作我的响应式网站的页脚。我正在使用媒体查询,如 Adsense 文档中所述,以便在不同的屏幕宽度下设置高度/宽度。

这是我的 CSS:

<style>

@media (min-width: 320px) {
    .adslot-desktop {
        width: 320px;
        height: 50px;
        display: inline-block;
    }
}

@media (min-width: 500px) {
    .adslot-desktop {
        width: 468px;
        height: 60px;
        display: inline-block;
    }
}
</style>

这是我的 HTML:

  <ins class="adsbygoogle adslot-desktop"
   data-ad-client="xxxxx"
   data-ad-slot="xxxxxx"
   data-ad-format="auto"></ins>

在屏幕宽度超过 500 像素时,我得到了预期的 468x60 广告。但是,低于 500 像素时,我会看到 320x100 的广告。

为什么它没有像我指定的那样为我提供 320x50 广告?

【问题讨论】:

    标签: html css adsense


    【解决方案1】:

    我曾经在 WP 中遇到过这样的问题,我唯一的想法就是更改媒体查询的顺序。不确定这里是否相同,但您可以尝试这样做。最高的 px 在顶部,然后向下。

    ** 我改用 max-width 让它工作

    @media (max-width: 500px) {
        .adslot-desktop {
            width: 468px;
            height: 60px;
            display: inline-block;
        }
    }
    
    @media (max-width: 320px) {
        .adslot-desktop {
            width: 320px;
            height: 50px;
            display: inline-block;
        }
    

    }

    【讨论】:

      【解决方案2】:

      我认为您需要删除data-ad-format,因为data-ad-format智能调整大小

      我们根据宽度动态计算所需尺寸 广告单元的父容器,然后确定最佳标准 高度与该宽度一致。

      关于自适应广告单元:
      https://support.google.com/adsense/answer/3213689

      你想要的是“每个屏幕宽度的确切尺寸”:

      <style>
      .adslot-desktop { width: 320px; height: 50px; }
      @media (min-width: 500px) { .adslot-desktop { width: 468px; height: 60px; } }
      </style>
       <ins class="adsbygoogle adslot-desktop"
        style="display:inline-block;"
        data-ad-client="xxxxx"
        data-ad-slot="xxxxxx"></ins>
      <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
      <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
      

      创建自适应广告单元 > 高级 > 每个屏幕宽度的确切尺寸:https://support.google.com/adsense/answer/3543893#adv

      【讨论】:

      • 这正是问题所在。我完全删除了 data-ad-format 属性,它就像一个魅力。在我的故障排除工作中,我试图将其设置为其他值,例如“水平”。感谢您的帮助。
      猜你喜欢
      • 1970-01-01
      • 2015-07-04
      • 2014-10-14
      • 2016-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-13
      • 2020-11-28
      相关资源
      最近更新 更多