@@ -1147,6 +1147,44 @@ Invisibility: the 'visibility' property</h2>
11471147 <em> is</em> rendered to speech,
11481148 and may be interacted with using non-visual/spatial methods.
11491149
1150+ <div class=example>
1151+ While temporarily hiding things with ''display: none''
1152+ is often sufficient,
1153+ doing so removes the elements from layout entirely,
1154+ possibly causing unwanted movement or reflow of the page
1155+ when an element is hidden or shown.
1156+ ''visibility: hidden'' can instead be used
1157+ to keep the page's layout stable
1158+ as something is hidden and displayed.
1159+
1160+ For example,
1161+ here is a (deliberately simplified) possible implementation of a "spoiler" element
1162+ that can be revealed by clicking on the hidden text:
1163+
1164+ <xmp highlight=markup>
1165+ <p> The symbolism earlier in the movie becomes obvious at the end,
1166+ when it's revealed that <spoiler-text><span> Luke is his own father</span></spoiler-text> ,
1167+ making the wizard's cryptic riddles meaningful.
1168+ <style>
1169+ spoiler-text { border-bottom: 1px solid; }
1170+ spoiler-text > span { visibility: hidden; }
1171+ spoiler-text.shown > span { visibility: visible; }
1172+ </style>
1173+ <script>
1174+ [...document.querySelectorAll("spoiler-text")] .forEach(el=>{
1175+ el.addEventListener("click", e=>el.classList.toggle("shown"));
1176+ });
1177+ </script>
1178+ </xmp>
1179+
1180+ Advisement: This example is deliberately significantly simplified.
1181+ It is missing a number of accessiblity and UX features
1182+ that a well-designed spoiler element would have
1183+ to show off the 'visibility' usage more plainly.
1184+ Don't copy this code for a real site.
1185+ </div>
1186+
1187+
11501188
11511189<!--
11521190████████ ██ ██ ██ ██ ████ ██ ██
0 commit comments