Not a bug Advertising not centered when site is in wider format

Bonsai Coder

Active member
Affected version
XenForo 2.0.1
Using the advertising function in the admin control panel, my ads are not getting centered when I have my site in a wide format (and yes I am refreshing when I change widths to test the responsive formatting.)

For example this screenshot of my site in a medium width shows the ad centered.

screenshot-www.bonsainut.com-2018-01-21-18-25-31.webp

When I widen the site, and hit refresh, the ad is not being centered.

screenshot-www.bonsainut.com-2018-01-21-18-26-31.webp

This may have something to do with the fact that I have maximum page width set to 1920px in the page setup options. However I have tested it with my ads in numerous locations (above node list, above thread list, below container) and they all fail to center
 
I don't believe this is XF related. The element is being created by Adsense and it is being given a width of 1200px in CSS. I have confirmed this specific behavior in 3 different browsers so it doesn't seem like it being a browser quirk (which we have seen in one other situation).

If you want to force that to always be centered, it would likely require some CSS changes for the ad code (unless it can be done within the ad configuration itself).
 
I don't believe this is XF related. The element is being created by Adsense and it is being given a width of 1200px in CSS.

The ad is centered in the 1200px block. The 1200 px block is being left aligned on the page, instead of centered.

If this is something I can fix manually with all my adsense blocks, if you could just point me in the right direction and give me a nudge, I'll do my best to fix it :)
 
Honestly, I'm not sure. The question is where the "1200px" value is coming from. It's being added to the Adsense element directly (by the Adsense JS). It does appear that you have 1200px set as your responsive "wide" value, but those should generally just be conditions, rather than something that Adsense would be picking up (I can't see any reason for it to be).
 
Honestly, I'm not sure. The question is where the "1200px" value is coming from.

Here's the script (with sensitive parts removed):

Code:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- BNUT Responsive Ad Main Site All Users -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-XXXXXXXXXXXXXXXXXXXX"
     data-ad-slot="XXXXXXXXXXXXXXXXXXX"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
 
I always use <center> before and </center> after on my Adsense

For instance
Code:
<center><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- BNUT Responsive Ad Main Site All Users -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-XXXXXXXXXXXXXXXXXXXX"
     data-ad-slot="XXXXXXXXXXXXXXXXXXX"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></center>
 
Last edited:
@CoZmicShReddeR

Ok let me ask the next question. For the ads below container, they are centering fine as long as there is no sidebar or sidenav. If both sidebar and sidenav are present (since they are currently formatted to be equal widths) there is no problem. However if only the sidebar is active, the ad is off-center again.
 
@CoZmicShReddeR

Ok let me ask the next question. For the ads below container, they are centering fine as long as there is no sidebar or sidenav. If both sidebar and sidenav are present (since they are currently formatted to be equal widths) there is no problem. However if only the sidebar is active, the ad is off-center again.

Well that is normal since the side nav pushes the content over...
 
Top Bottom