fix: avoid layout shift due to ads (#176)

pull/212/head
Eduardo San Martin Morote 4 years ago committed by GitHub
parent 51906043d3
commit 78b026cb7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,12 +36,16 @@
<Page v-else> <Page v-else>
<template #top> <template #top>
<slot name="page-top-ads"> <slot name="page-top-ads">
<div
id="ads-container"
v-if="theme.carbonAds && theme.carbonAds.carbon"
>
<CarbonAds <CarbonAds
v-if="theme.carbonAds"
:key="'carbon' + page.relativePath" :key="'carbon' + page.relativePath"
:code="theme.carbonAds.carbon" :code="theme.carbonAds.carbon"
:placement="theme.carbonAds.placement" :placement="theme.carbonAds.placement"
/> />
</div>
</slot> </slot>
<slot name="page-top" /> <slot name="page-top" />
</template> </template>
@ -154,3 +158,34 @@ const pageClasses = computed(() => {
] ]
}) })
</script> </script>
<style>
#ads-container {
margin: 0 auto;
}
@media (min-width: 420px) {
#ads-container {
position: relative;
right: 0;
float: right;
margin: -8px -8px 24px 24px;
width: 146px;
}
}
@media (max-width: 420px) {
#ads-container {
/* Avoid layout shift */
height: 105px;
}
}
@media (min-width: 1400px) {
#ads-container {
position: fixed;
right: 8px;
bottom: 8px;
}
}
</style>

@ -26,21 +26,19 @@ onMounted(() => {
border-radius: 4px; border-radius: 4px;
margin: 0 auto; margin: 0 auto;
max-width: 280px; max-width: 280px;
font-size: .75rem; font-size: 0.75rem;
background-color: rgba(255, 255, 255, .8); background-color: rgba(255, 255, 255, 0.8);
min-height: 105.38px; /* avoid layout shift on mobile */ min-height: 105.38px; /* avoid layout shift on mobile */
} }
.carbon-ads::after { .carbon-ads::after {
clear: both; clear: both;
display: block; display: block;
content: ""; content: '';
} }
@media (min-width: 420px) { @media (min-width: 420px) {
.carbon-ads { .carbon-ads {
position: relative;
right: -8px;
z-index: 1; z-index: 1;
float: right; float: right;
margin: -8px -8px 24px 24px; margin: -8px -8px 24px 24px;
@ -53,10 +51,7 @@ onMounted(() => {
@media (min-width: 1400px) { @media (min-width: 1400px) {
.carbon-ads { .carbon-ads {
position: fixed;
top: auto;
right: 8px; right: 8px;
bottom: 8px;
float: none; float: none;
margin: 0; margin: 0;
} }
@ -64,7 +59,7 @@ onMounted(() => {
.carbon-ads :deep(.carbon-img) { .carbon-ads :deep(.carbon-img) {
float: left; float: left;
margin-right: .75rem; margin-right: 0.75rem;
max-width: 100px; max-width: 100px;
border: 1px solid var(--c-divider); border: 1px solid var(--c-divider);
} }

Loading…
Cancel
Save