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

时间:2022-08-24 07:40:04

I had 2 x (300x250) Adsense ad units in the right side bar of my site

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

I have made the site responsive and replaced these ad units with Adsense responsive ad units.

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

The problem i now have is that Adsense is now serving 2 x (300x600) ad units. Adsense TOS state that you can only serve 1 (300x600) ad unit per page

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

The max width is obviously getting picked up by adsense responsive ad units.

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

But when I try and set the max-height of the parent div to 250px, to limit the number of 300x600 ads per page, the max-height gets ignored and adsense still displays a 300x600

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

Has anyone else encountered this problem and if so, how did you manage to set the max-height of the responsive ad unit?

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

Thanks in advance,

提前致谢,

Kes

凯斯

4 个解决方案

#1


51  

You could change data-ad-format="auto" to data-ad-format="rectangle". (See Advanced features > Horizontal shape example.)

您可以将data-ad-format =“auto”更改为data-ad-format =“rectangle”。 (请参阅高级功能>水平形状示例。)

I think you should not define height (max-height) on parent div.

我认为你不应该在父div上定义高度(max-height)。

Ad height is (automatically) determined by adsbygoogle.js (that is smart sizing) and if you want to control ad height you need to use data-ad-format ("rectangle", "vertical", "horizontal" or your preferred combination like "rectangle,horizontal").

广告高度(自动)由adsbygoogle.js确定(即智能大小),如果您想控制广告高度,则需要使用数据广告格式(“矩形”,“垂直”,“水平”或您首选的组合像“矩形,水平”)。

Or (not recommended) you could "downgrade" the ad code (by removing data-ad-format attribute) and then specify the exact size(s) with @media queries. (See Exact size example.)

或者(不推荐)您可以“降级”广告代码(通过删除data-ad-format属性),然后使用@media查询指定确切的大小。 (参见确切尺寸示例。)


EDIT - Google updated "Technical considerations" section on "About responsive ad units" page.

编辑 - Google更新了“关于自适应广告单元”页面上的“技术注意事项”部分。

There are some situations in which you’ll need to take extra action to make a responsive ad unit work correctly:

在某些情况下,您需要采取额外措施才能使响应式广告单元正常工作:

...

...

The parent container has fixed or limited height. Responsive ads should not be placed inside containers with a fixed or limited height, as they may be taller on some devices or browsers. If you need to limit the height of your responsive ads, you’ll need to modify your code and use CSS media queries to set the height of the parent container. Find out how to modify your responsive ad unit.

父容器具有固定或有限的高度。响应式广告不应放置在具有固定或有限高度的容器内,因为它们在某些设备或浏览器上可能更高。如果您需要限制自适应广告的高度,则需要修改代码并使用CSS媒体查询来设置父容器的高度。了解如何修改自适应广告单元。

#2


6  

I've just managed to fix this - you can set a comma seperated list for data-ad-format.

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

data-ad-format="rectangle, horizontal"

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

This sets the mobile ad to horizontal and the desktop to rectangle if you have set your media queries specific sizes.

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

Thanks, Wesiwyg

谢谢,Wesiwyg

#3


2  

You can do it by using CSS in <ins style="display:inline-block;......"> or specifying a class <ins class="adsbygoogle ......">

你可以在中使用CSS或指定一个类

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

来自Google AdSense答案的示例:指定可展开的宽度和固定的高度

You may modify your responsive ad code to specify an expandable width and a fixed height for your ad unit via CSS. The following example shows you how to make these modifications:

您可以修改自适应广告代码,以通过CSS为广告单元指定展开式宽度和固定高度。以下示例说明如何进行这些修改:

Expandable width with fixed height example

具有固定高度示例的可扩展宽度

This example shows you how to modify your responsive ad code to specify a fixed height of 90px and a variable width from min-width 400px to max-width 970px:

此示例显示如何修改自适应广告代码,以指定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>

From Policies and restrictions:

来自政策和限制:

Additionally, the following size restrictions will be enforced:

此外,将强制执行以下大小限制:

  • Only one dimension can be greater than 300 pixels
  • 只有一个维度可以大于300个像素
  • The minimum width is 120 pixels
  • 最小宽度为120像素
  • The minimum height is 50 pixels
  • 最小高度为50像素
  • Neither height nor width can exceed 1200 pixels.
  • 高度和宽度都不能超过1200像素。

#4


0  

To get this done, First set the ad container or ad code to center. by using this tag: <center>Adsense code here</center>. and then set the maximum height or width and minimum height or width like the way I did in the example below.

要完成此操作,请先将广告容器或广告代码设置为中心。使用此标签:

Adsense code here 。然后设置最大高度或宽度以及最小高度或宽度,就像我在下面的示例中所做的那样。


<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>`

#1


51  

You could change data-ad-format="auto" to data-ad-format="rectangle". (See Advanced features > Horizontal shape example.)

您可以将data-ad-format =“auto”更改为data-ad-format =“rectangle”。 (请参阅高级功能>水平形状示例。)

I think you should not define height (max-height) on parent div.

我认为你不应该在父div上定义高度(max-height)。

Ad height is (automatically) determined by adsbygoogle.js (that is smart sizing) and if you want to control ad height you need to use data-ad-format ("rectangle", "vertical", "horizontal" or your preferred combination like "rectangle,horizontal").

广告高度(自动)由adsbygoogle.js确定(即智能大小),如果您想控制广告高度,则需要使用数据广告格式(“矩形”,“垂直”,“水平”或您首选的组合像“矩形,水平”)。

Or (not recommended) you could "downgrade" the ad code (by removing data-ad-format attribute) and then specify the exact size(s) with @media queries. (See Exact size example.)

或者(不推荐)您可以“降级”广告代码(通过删除data-ad-format属性),然后使用@media查询指定确切的大小。 (参见确切尺寸示例。)


EDIT - Google updated "Technical considerations" section on "About responsive ad units" page.

编辑 - Google更新了“关于自适应广告单元”页面上的“技术注意事项”部分。

There are some situations in which you’ll need to take extra action to make a responsive ad unit work correctly:

在某些情况下,您需要采取额外措施才能使响应式广告单元正常工作:

...

...

The parent container has fixed or limited height. Responsive ads should not be placed inside containers with a fixed or limited height, as they may be taller on some devices or browsers. If you need to limit the height of your responsive ads, you’ll need to modify your code and use CSS media queries to set the height of the parent container. Find out how to modify your responsive ad unit.

父容器具有固定或有限的高度。响应式广告不应放置在具有固定或有限高度的容器内,因为它们在某些设备或浏览器上可能更高。如果您需要限制自适应广告的高度,则需要修改代码并使用CSS媒体查询来设置父容器的高度。了解如何修改自适应广告单元。

#2


6  

I've just managed to fix this - you can set a comma seperated list for data-ad-format.

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

data-ad-format="rectangle, horizontal"

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

This sets the mobile ad to horizontal and the desktop to rectangle if you have set your media queries specific sizes.

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

Thanks, Wesiwyg

谢谢,Wesiwyg

#3


2  

You can do it by using CSS in <ins style="display:inline-block;......"> or specifying a class <ins class="adsbygoogle ......">

你可以在中使用CSS或指定一个类

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

来自Google AdSense答案的示例:指定可展开的宽度和固定的高度

You may modify your responsive ad code to specify an expandable width and a fixed height for your ad unit via CSS. The following example shows you how to make these modifications:

您可以修改自适应广告代码,以通过CSS为广告单元指定展开式宽度和固定高度。以下示例说明如何进行这些修改:

Expandable width with fixed height example

具有固定高度示例的可扩展宽度

This example shows you how to modify your responsive ad code to specify a fixed height of 90px and a variable width from min-width 400px to max-width 970px:

此示例显示如何修改自适应广告代码,以指定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>

From Policies and restrictions:

来自政策和限制:

Additionally, the following size restrictions will be enforced:

此外,将强制执行以下大小限制:

  • Only one dimension can be greater than 300 pixels
  • 只有一个维度可以大于300个像素
  • The minimum width is 120 pixels
  • 最小宽度为120像素
  • The minimum height is 50 pixels
  • 最小高度为50像素
  • Neither height nor width can exceed 1200 pixels.
  • 高度和宽度都不能超过1200像素。

#4


0  

To get this done, First set the ad container or ad code to center. by using this tag: <center>Adsense code here</center>. and then set the maximum height or width and minimum height or width like the way I did in the example below.

要完成此操作,请先将广告容器或广告代码设置为中心。使用此标签:

Adsense code here 。然后设置最大高度或宽度以及最小高度或宽度,就像我在下面的示例中所做的那样。


<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>`