首页 文章

设置Adsense响应式广告单元的最大高度

提问于
浏览
35

我的网站右侧栏中有2个(300x250)Adsense广告单元

我使网站响应迅速,并将这些广告单元替换为Adsense响应式广告单元 .

我现在的问题是,Adsense现在提供2 x(300x600)广告单元 . Adsense TOS声明您每页只能投放1(300x600)个广告单元

最大宽度显然会被adsense响应式广告单元所吸引 .

但是,当我尝试将父div的最大高度设置为250px时,为了限制每页300x600的广告数量,最大高度会被忽略,而adsense仍会显示300x600

是否有其他人遇到此问题,如果是,您是如何设置响应广告单元的最大高度的?

提前致谢,

凯斯

4 回答

  • 2

    您可以将 data-ad-format="auto" 更改为 data-ad-format="rectangle" . (请参阅高级功能> Horizontal shape example . )

    我认为你应该 not 在父 div 上定义 heightmax-height ) .

    广告高度(自动)由 adsbygoogle.js (即 smart 大小调整)确定,如果您想控制广告高度,则需要使用 data-ad-format ("rectangle","vertical","horizontal"或preferred combination,如"rectangle,horizontal") .

    或者(不推荐)您可以"downgrade"广告代码(通过删除 data-ad-format 属性)然后使用@ media 查询指定 exact 尺寸 . (见Exact size example . )


    EDIT - Google在“About responsive ad units”页面上更新了"Technical considerations"部分 .

    在某些情况下,您需要采取额外操作才能使响应式广告单元正常工作:...父容器的高度是固定的或有限的 . 响应广告不应放置在具有固定或有限高度的容器内,因为它们在某些设备或浏览器上可能更高 . 如果您需要限制自适应广告的高度,则需要修改代码并使用CSS媒体查询来设置父容器的高度 . 了解如何修改自适应广告单元 .

  • 0

    我刚刚设法解决了这个问题 - 您可以为数据广告格式设置逗号分隔列表 .

    data-ad-format =“矩形,水平”

    如果您已将媒体查询设置为特定尺寸,则会将移动广告设置为水平,将桌面设置为矩形 .

    谢谢,Wesiwyg

  • 55

    您可以在 <ins style="display:inline-block;......"> 中使用CSS或指定类 <ins class="adsbygoogle ......"> 来实现

    示例 from Google AdSense answers: Specify an expandable width and a fixed height

    您可以修改自适应广告代码,以通过CSS为广告单元指定展开式宽度和固定高度 . 以下示例说明如何进行这些修改:具有固定高度的可扩展宽度示例此示例显示如何修改响应式广告代码以指定固定高度90px和可变宽度,从最小宽度400px到最大宽度970px:

    <ins class="adsbygoogle"
       style="display:inline-block;min-width:400px;max-width:970px;width:100%;height:90px"
       data-ad-client="ca-pub-1234"
       data-ad-slot="5678"></ins>
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
    

    来自Policies and restrictions

    此外,将强制执行以下尺寸限制:只有一个尺寸可以大于300像素最小宽度为120像素最小高度为50像素高度和宽度都不能超过1200像素 .

  • 6

    要完成此操作,请先将广告容器或广告代码设置为中心 . 使用此标签: <center>Adsense code here</center> . 然后设置最大高度或宽度以及最小高度或宽度,就像我在下面的示例中所做的那样 .


    <center>
      <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js">
      </script>
      <!--responsive ad -->
      <ins class="adsbygoogle" style="display:block;max-width:specify your maximum width here; max-height: set o your maximum height here; and do the same for min-height:here;min-width:here;"
          data-ad-client="ca-pub-0019"
          data-ad-slot="530000000000"
          data-ad-format="auto"></ins>
      <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
      </script>
    </center>`
    

相关问题