Skip to content

Commit 987a8f5

Browse files
authored
Pre-style to avoid Layout Shift (#487)
* Add pre-styling to avoid Layout Shift (and appropriate resets) * Remove scrollbars in index.html
1 parent 7c743d7 commit 987a8f5

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

index-map-area.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
map[is="web-map"]:not(:defined) > :not(area):not(.mapml-web-map) {
3737
display: none;
3838
}
39+
40+
/* Pre-style to avoid Layout Shift. */
41+
map[is="web-map"]:not(:defined) {
42+
display: inline-block;
43+
contain: size;
44+
contain-intrinsic-size: 304px 154px;
45+
}
46+
3947
/* Ensure inline layer content is hidden if custom/built-in elements isn't
4048
supported, or if javascript is disabled. This needs to be defined separately
4149
from the above, because the `:not(:defined)` selector invalidates the entire
@@ -51,6 +59,14 @@
5159
map[is="web-map"]:not(:defined) + img[usemap] {
5260
display: initial;
5361
}
62+
63+
/* "Reset" the properties used to pre-style (to avoid Layout Shift) if
64+
custom/built-in elements is supported but javascript is disabled. */
65+
map[is="web-map"]:not(:defined) {
66+
display: initial;
67+
contain: initial;
68+
contain-intrinsic-size: initial;
69+
}
5470
</style>
5571
</noscript>
5672
</head>

index-mapml-viewer.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
mapml-viewer:not(:defined) > * {
3636
display: none;
3737
}
38+
39+
/* Pre-style to avoid Layout Shift. */
40+
mapml-viewer:not(:defined) {
41+
display: inline-block;
42+
contain: size;
43+
contain-intrinsic-size: 304px 154px;
44+
}
45+
3846
/* Ensure inline layer content is hidden if custom/built-in elements isn't
3947
supported, or if javascript is disabled. This needs to be defined separately
4048
from the above, because the `:not(:defined)` selector invalidates the entire
@@ -50,6 +58,14 @@
5058
mapml-viewer:not(:defined) > :not(layer-) {
5159
display: initial;
5260
}
61+
62+
/* "Reset" the properties used to pre-style (to avoid Layout Shift) if
63+
custom/built-in elements is supported but javascript is disabled. */
64+
mapml-viewer:not(:defined) {
65+
display: initial;
66+
contain: initial;
67+
contain-intrinsic-size: initial;
68+
}
5369
</style>
5470
</noscript>
5571
</head>

index-web-map.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
map[is="web-map"]:not(:defined) > :not(area):not(.mapml-web-map) {
3737
display: none;
3838
}
39+
40+
/* Pre-style to avoid Layout Shift. */
41+
map[is="web-map"]:not(:defined) {
42+
display: inline-block;
43+
contain: size;
44+
contain-intrinsic-size: 304px 154px;
45+
}
46+
3947
/* Ensure inline layer content is hidden if custom/built-in elements isn't
4048
supported, or if javascript is disabled. This needs to be defined separately
4149
from the above, because the `:not(:defined)` selector invalidates the entire
@@ -51,6 +59,14 @@
5159
map[is="web-map"]:not(:defined) + img[usemap] {
5260
display: initial;
5361
}
62+
63+
/* "Reset" the properties used to pre-style (to avoid Layout Shift) if
64+
custom/built-in elements is supported but javascript is disabled. */
65+
map[is="web-map"]:not(:defined) {
66+
display: initial;
67+
contain: initial;
68+
contain-intrinsic-size: initial;
69+
}
5470
</style>
5571
</noscript>
5672
</head>

index.html

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,23 @@
2828
height: 100%;
2929

3030
/* Remove default (native-like) border. */
31-
/* border: none; */
31+
border: none;
32+
33+
vertical-align: middle;
3234
}
3335

3436
/* Pre-style to avoid FOUC of inline layer- and fallback content. */
3537
mapml-viewer:not(:defined) > * {
3638
display: none;
3739
}
40+
41+
/* Pre-style to avoid Layout Shift. */
42+
mapml-viewer:not(:defined) {
43+
display: inline-block;
44+
contain: size;
45+
contain-intrinsic-size: 304px 154px;
46+
}
47+
3848
/* Ensure inline layer content is hidden if custom/built-in elements isn't
3949
supported, or if javascript is disabled. This needs to be defined separately
4050
from the above, because the `:not(:defined)` selector invalidates the entire
@@ -50,6 +60,14 @@
5060
mapml-viewer:not(:defined) > :not(layer-) {
5161
display: initial;
5262
}
63+
64+
/* "Reset" the properties used to pre-style (to avoid Layout Shift) if
65+
custom/built-in elements is supported but javascript is disabled. */
66+
mapml-viewer:not(:defined) {
67+
display: initial;
68+
contain: initial;
69+
contain-intrinsic-size: initial;
70+
}
5371
</style>
5472
</noscript>
5573
</head>

0 commit comments

Comments
 (0)