Limiting the height of Adsense's responsive ad unit

Before, I had 2 x (300x250) Adsense ad units on the right side bar of my website.

Recently, I made my site responsive and replaced those ad units with Adsense responsive ad units.

Now, the issue is that Adsense is serving 2 x (300x600) ad units when their Terms of Service only allow for 1 (300x600) ad unit per page.

The maximum width seems to be causing Adsense to display the larger ad units.

Even when I try to set the max-height of the parent div to 250px to restrict the number of 300x600 ads shown, Adsense ignores it and displays them anyway.

Has anyone else faced this problem, and if so, how did you successfully limit the height of the responsive ad unit?

Thank you in advance,

Kes

Answer №1

To enhance the display, you may consider changing data-ad-format="auto" to data-ad-format="rectangle". For more details, check out the Advanced features section and view the Horizontal shape example.

In my opinion, it is advisable to avoid specifying the height (or max-height) on the parent div.

The ad height is automatically adjusted by adsbygoogle.js through smart sizing. If you wish to manage the ad's height, utilize the data-ad-format attribute with options like "rectangle", "vertical", "horizontal", or a customized combination such as "rectangle,horizontal".

Alternatively (although not recommended), you could eliminate the data-ad-format attribute from the ad code and then set specific size(s) using @media queries. Refer to the Exact size example for guidance.


UPDATE - Google has made changes to the "Technical considerations" segment in the "About responsive ad units" page.

In certain scenarios, additional measures must be taken to ensure that a responsive ad unit functions correctly:

...

The parent container has fixed or limited height. It is important not to place responsive ads within containers of fixed or restricted height, as they might appear differently on various devices or browsers. To restrict the height of your responsive ads, adjustments need to be made in your code using CSS media queries to determine the parent container's height. Learn how to make these changes by visiting the guide on modifying your responsive ad unit.

Answer №2

Great news - I successfully resolved this issue by utilizing a comma-separated list for data-ad-format.

data-ad-format="rectangle, horizontal"

By doing this, the mobile ad will display in a horizontal format and the desktop ad will be shown as a rectangle, provided that you have specified sizes in your media queries.

Best regards, Wesiwyg

Answer №3

My current successful setup as of October 2020:

<ins class="adsbygoogle"
     style="display:inline-block;min-width:300px;max-width:900px;width:100%;height:60px"
     data-ad-client="ca-pub-yyy"
     data-ad-format="fluid-responsive"
     data-ad-slot="yyy"></ins>

Answer №4

When I was working in January 2020, here are the changes that worked for me:

1 - I disabled the "auto size for mobile" option.

2 - I set a fixed "non-responsive" ad size instead of the default value.

3 - You can add your own code and use CSS to customize the size as needed. For example:

<ins class="adsbygoogle" style="display:inline-block;width:100%;height:100px" data-ad-client="****" data-ad-slot="****"></ins>

With this code, my ads always take up 100% of the width and a maximum of 100px in height. You can also consider adding values for "min-width" and "max-width".

There are three conditions that could unknowingly resize your ad:

1 - If the ad is responsive

2 - If the "optimize size of ads on mobile" setting is enabled

3 - If the global "automatic ads" is turned on with "Optimize your existing ad units?" set to on.

Answer №5

My preferred option would be the following:

style="display:inline-block;min-width:200px;max-width:300px;width:100%;height:250px"
data-ad-format="horizontal"></ins>

This method is recommended by Google itself and has proven to be effective for me:

https://support.google.com/adsense/answer/9467650?hl=en-GB

Answer №6

In order to achieve this, start by centering the ad container or ad code using the following tag:

<center>Adsense code here</center>
. Then, specify the maximum and minimum height or width as demonstrated in the example below.


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

Answer №7

Starting from the beginning of 2020, I have found that setting max-height on ins elements seems to function properly without any glitches (as long as it is applied to the parent container, not directly). Here is an example of how I am utilizing this in a production setting:

<ins class="adsbygoogle"
     style="display:block; max-height: 336px"
     data-ad-client="ca-pub-XXXXXX"
     data-ad-slot="YYYYYY"
     data-ad-format="auto"></ins>

UPDATE: It has been officially confirmed that this method is supported since August 2019. More information can be found at https://support.google.com/adsense/answer/9467650?hl=en

Answer №8

The following code snippet is provided on the Google AdSense help page for creating responsive ads:

<style>
.responsive_ad { width: 320px; height: 100px; }
@media(min-width: 500px) { .responsive_ad { width: 468px; height: 60px; } }
@media(min-width: 800px) { .responsive_ad { width: 728px; height: 90px; } }
</style>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXX11XXX9" crossorigin="anonymous"></script>
<!-- responsive_ad -->
<ins class="adsbygoogle responsive_ad"
     style="display:inline-block"
     data-ad-client="ca-pub-XXXXXXX11XXX9"
     data-ad-slot="8XXXXX1"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

For more information, please visit https://support.google.com/adsense/answer/9183363?hl=en

Answer №9

<style>.custom_responsive_1 { width: 320px; height: 100px; }@media(min-width: 500px) { .custom_responsive_1 { width: 468px; height: 60px; } }@media(min-width: 800px) { .custom_responsive_1 { width: 728px; height: 90px; } }</style><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- custom_responsive_1 --><ins class="adsbygoogle custom_responsive_1"     style="display:inline-block"     data-ad-client="ca-pub-XXXXXXX11XXX9"     data-ad-slot="8XXXXX1"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({}); </script>

Give this a shot

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensure that the Left and Right menu are fixed in position, while allowing the middle content to be scrollable

I'm in the process of creating a web page with a fixed left and right menu, while the middle content should be scrollable and positioned behind the menus. I've attempted to implement this using the following HTML and CSS, but encountered an error ...

Issue with displaying sidebar using blockquote in Bootstrap 4.1.3

After implementing the blockquote class in Bootstrap 4.1.3, all the effects were successfully applied, except for the sidebar. Here's a comparison of how it appears in tutorials: https://i.sstatic.net/qNXrV.png And here is how it appears in my Chrom ...

The Safari 7.1+ browser seems to be having trouble with the spotlight effect

Why is the CodePen not functioning properly in Safari? Despite working well in Chrome and Firefox, it completely fails to work in Safari 7.1+. Can anyone provide some insights? http://codepen.io/cchambers/pen/Dyldj $(document).on("mousemove", function( ...

Misplaced SVG background images causing layout issues

I am trying to create a unique effect on an SVG image by overlaying color images on top of it through paths with background images. The goal is to make it appear as though parts of the image transition into color when hovered over. If you want to see the ...

Is anyone else seeing a mysterious gray outline surrounding the image?

When visiting my website, I encountered an issue with the main menu. Specifically, when hovering over 'Populaire boeken', the first 2 menu items display properly with an image on mouseover. However, there seems to be a pesky grey border surroundi ...

Can the Caption Adapt to the Image?

Code snippet: <script type="text/javascript> function displayNextImage() { x = (x === images.length - 1) ? 0 : x + 1; document.getElementById("img").src = images[x]; } function displayPreviousImage() { x = ...

What are some ways to apply selector combinators to hashed CSS module classes?

Seeking advice on overriding a style in a CSS module for a third-party datepicker component used within a custom component. The challenge lies in targeting the correct element with a selector combinator, complicated by the dynamic creation of class names i ...

Unable to load CSS in Node.js when the parameter in Express.js is too long

I have been working on an application using Node.js, express.js, and ejs. I am utilizing the following code to incorporate ejs and load css: app.engine('.html', require('ejs').__express); app.set('views', __dirname + '/vi ...

What is the best way to eliminate the extra spacing on the right side of my navigation bar?

Hello everyone! I am diving into the world of HTML and CSS, but I've hit a roadblock. Despite searching through various resources and forums, I can't seem to find a solution to my problem. The issue at hand involves an irritating space in my nav ...

Ensuring uniformity in picture size while uploading images in Angular by resizing and including white borders

Currently, I am working with pictograms and I am looking to showcase all the pictograms that the user has in both grid list and grid tiles formats. However, the challenge lies in the fact that the aspect ratio of the pictograms varies significantly depen ...

Arrangement of layers while adjusting browser size

As I resize my browser window, the blue buttons shift below the logo on the left, aligning with the text "Welcome Bart" even though they belong to separate layers. I would like the text "Welcome Bart" to also move downwards so that they are not on the same ...

Creating a dynamic dropdown list populated with Jinja templates

I am currently working on a Flask application where one of the routes generates a list of data that I intend to display in a dropdown menu on the front-end. The challenge lies in the fact that each list may vary in length, with different users having diffe ...

What is the best way to update just the image path in the source using jQuery?

I am currently working on implementing a dark mode function for my website, and I have successfully adjusted the divs and other elements. However, I am facing an issue with changing the paths of images. In order to enable dark mode, I have created two sep ...

Unable to Utilize Custom Colors in Tailwind CSS within NextJS

I am currently experimenting with NextJs and Tailwinds CSS for a new project. However, I keep encountering an error when attempting to apply a custom background color: Failed to compile ./styles/globals.css:7:12 Syntax error: /Users/anishkunapareddy/Deskto ...

What is the significance of positioning a:hover after a:link and a:visited?

While studying CSS, I encountered a confusing rule that states ':hover' must come after ':link' and ':visited'. In practice, to visit a link we first need to click on it, and in order to click the link, we usually hover over ...

Issue with Dotless MVC bundling occurring when attempting to import a specific less file multiple times

Trying to achieve a specific structure using dotless: styles/variables.less - contains all variables like this @color:green; styles/component1.less - random component specific style importing variables.less @import "variables"; body { ba ...

What is the best way to conceal part of a chart or a div in Angular?

I have a large chart that I need to showcase on my website, but due to its size it would take up too much vertical space and potentially overwhelm the user upon their first visit. My goal is to provide a preview of the chart, similar to an excerpt of text ...

Is it possible to customize the default translucent image that appears when the onDragStart event is triggered in a browser?

Hey everyone, I hope you're all doing great. Firstly, I want to express my gratitude for your support in trying to improve my skills. My current project involves developing a simple drag-and-drop feature for an existing list as part of a practice exer ...

Which library does stackoverflow utilize to showcase errors (utilizing Bootstrap popover for error help-block)?

Currently, I am using bootstrap's has-error and help-block classes to display validation error messages in my form. However, I find the error message display in Stackoverflow's Ask Questions Form to be very appealing. Are they using a specific js ...

What is the technique for creating a repeating image rather than stretching it?

Is there a way to repeat a background image to fit its content? I have a background image that needs to be repeated in this manner: https://i.sstatic.net/qVKkp.png However, when using the following code: .imgbord { background: url('https://i.imgur ...