Skip to content

Commit ecad67a

Browse files
authored
Fix ad iframe whitespace (#14193)
1 parent 5d10f9a commit ecad67a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

dotcom-rendering/src/lib/adStyles.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,28 @@ const adSlotContainerStyles = css`
4545

4646
const adSlotStyles = css`
4747
.ad-slot {
48-
/* this is centring the ad iframe as they are display: inline; elements by default */
49-
text-align: center;
48+
/* used by native ads that set a background using messenger e.g. fabric that set a background outside of the ad using an absolutely positioned element */
49+
position: relative;
50+
51+
width: fit-content;
52+
margin-left: auto;
53+
margin-right: auto;
5054
5155
/*
5256
Ensure that the ad slot is centred,
5357
the element with this class name is inserted by GAM into the ad slot
5458
*/
5559
.ad-slot__content {
56-
margin-left: auto;
57-
margin-right: auto;
60+
/* When a native ad is served, GAM sets this to inline-block as an inline style, but we want it to be block as inline-block can cause whitespace to render newlines as white space, see https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Whitespace#:~:text=If%20there%20is%20formatting%20whitespace%20between%20adjacent%20inline%20elements%2C%20this%20will%20result%20in%20space%20in%20the%20layout%2C%20just%20like%20the%20spaces%20between%20words%20in%20text. */
61+
/* stylelint-disable-next-line declaration-no-important */
62+
display: block !important;
63+
64+
/* iframes are inline by default, so we need to set them to block to avoid the same whitespace quirk mentioned in the above comment */
65+
iframe {
66+
display: block;
67+
margin-left: auto;
68+
margin-right: auto;
69+
}
5870
}
5971
6072
@media print {

0 commit comments

Comments
 (0)