如何使自适应Google-adsense广告按尺寸调整大小? [英] How to make responsive Google-adsense ads scale on resize?
问题描述
我正在使用Google Adsense自适应广告(通过Bootstrap),并且在页面加载时可以正常使用。同样在手持设备中,它可以正确检测方向并立即调整广告。
I am using google adsense responsive ads (with Bootstrap) and it works properly on page load. Also in a hand-held device it detects the orientation properly and adjusts the ads immediatly.
但是,当我调整浏览器大小时,它不会对此做出反应。奇怪的是,当没有内置系统可以检测屏幕尺寸时,要求响应。我曾考虑过添加一个事件监听器,但这是一个很好的解决方法,还是会失败?我还考虑过加载带有不同断点的不同尺寸的广告,但我想避免这种情况,而只使用响应式广告。
However, when I resize my browser it does not react to it. Weird to claim responsiveness when there is no build in system to detect screen resize. I have thought to add an eventlistener, but is this a good work around or will it break? I also thought of loading in different ad sizes with a few break point but I would like to avoid that and just use the "responsive" ad.
在此先感谢您
推荐答案
在自适应广告中,将data-ad-format的 auto更改为 horizontal
In the responsive ad, change data-ad-format "auto" to "horizontal"
data-ad-format="horizontal"
还添加了媒体查询移动高度限制。
Also add a media query mobile height restriction.
.adsense-mobile {
height: 60px;
}
最终:
<ins class="adsbygoogle adsense-mobile"
style="display:block"
data-ad-client="ca-pub-XXXXXX"
data-ad-slot="XXXXXX"
data-ad-format="horizontal"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
这篇关于如何使自适应Google-adsense广告按尺寸调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!