admin管理员组

文章数量:1123089

I have an ad unit at the top of my site, on desktop views it fills with a 970x250 ad unit.

I have the ad unit injected inside a div that is 250px tall.

Here's some pseudo code showing the markup:

<body>
<aside class="top_ad_unit">
  <div class="ad__desktop ad__window" data-ad='div-gpt-ad-flex'></div>
</aside>
<div>
..the rest of the site below...

CSS like so:

.top_ad_unit {
  display: flex;
  flex-flow: row nowrap;
  justify-content: center;
  background: #cdcdcd;
}

@media (min-width: 1120px) {
  .top_ad_unit {
  height: 250px;
  }
}

And that CSS is inline as part of my critical path CSS.

So I'd think that the height of the div means that the ad won't cause any layout shift. The div is already there and already the correct height to encapsulate the ad, wether it loads fast, loads slow, or doesn't fill at all.

And that seems to be how it looks visually and when loading the page in Chrome's performance tab. But when I actually run the performance tab, it's showing this add as causing a layout shift and I'm baffled as to why.

Any insight would be appreciated! TY!

本文标签: htmlHow can an iframe (ad) filling a div with an already defined height cause a layout shiftStack Overflow