简体   繁体   中英

Limit footer height to 100px with Google responsive add

I have a website with a google map on it which I am trying to place a google ad at the bottom on a footer that can eventually be dismissed. Right now I am struggling with holding the height of the footer to 100px once I put a responsive ad sense ad in it.

I tried following the google Adsense api with this:

     <div class="footer" style="height:100px !important">

<style>
.example_responsive_1 { width: 320px; height: 100px; }
@media(min-width: 500px) { .example_responsive_1 { width: 468px; height: 60px; } }
@media(min-width: 800px) { .example_responsive_1 { width: 728px; height: 90px; } }
</style>          
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Anchor Ad -->
<ins class="adsbygoogle example_responsive_1"
     style="display:block"
     data-ad-client="ca-pub-3213091474519287"
     data-ad-slot="6029013039"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

        </div> 

But it keeps jumping up much larger than 100px. You can see the code live here: https://www.seekadventure.net/adventureMap2.html

The ads script appears to do two things:

  • it overwrites your inline styling on your .footer with height: auto !important
  • it contains inline styling on the add itself.

What you could do is place !important after each of your style declarations (for example:

.example_responsive_1 { width: 320px; height: 100px !important; }
@media(min-width: 500px) { .example_responsive_1 { width: 468px; height: 60px!important; } }
@media(min-width: 800px) { .example_responsive_1 { width: 728px; height: 90px !important; } }

While this does solve the footer sizing problem, it creates a different one: displaying the adds in a page real-estate only 100px tall - which appears to be the reason why the script overwrites the host element's height value in the first place.

One thing you could do to improve this is:

.example_responsive_1 {
  transform: scale(calc(10/28));
  transform-origin: top;
}

Another would be to make the footer's background transparent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM