custom-highlight-dynamic-container-metrics-003.html (1505B)
1 <!DOCTYPE html> 2 <meta charset="UTF-8"> 3 <title>CSS Highlight API Test: Highlights using dynamic container sizes</title> 4 <link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/"> 5 <link rel="help" href="https://drafts.csswg.org/css-pseudo/#highlight-styling"> 6 <link rel="help" href="https://drafts.csswg.org/css-conditional-5/#container-lengths"> 7 <link rel="match" href="custom-highlight-container-metrics-003-ref.html"> 8 <meta name="assert" value="lengths depending on containers update correctly for a highlight defined only inside a container query"> 9 <head> 10 <style> 11 .wrapper { 12 container: wrapper / size; 13 width: 400px; 14 height: 200px; 15 } 16 .resize { 17 width: 200px; 18 height: 100px; 19 } 20 @container (width < 300px) { 21 ::highlight(highlight1) { 22 text-underline-offset: 2cqw; 23 text-decoration-line: underline; 24 text-decoration-color: green; 25 text-decoration-thickness: 4cqh; 26 } 27 } 28 </style> 29 </head> 30 <body> 31 <div id="container" class="wrapper"> 32 <div id="h1">With container size</div> 33 </div> 34 <div id="h2">Should be no highlight</div> 35 <script> 36 let r1 = new Range(); 37 r1.setStart(h1, 0); 38 r1.setEnd(h1, 1); 39 let r2 = new Range(); 40 r2.setStart(h2, 0); 41 r2.setEnd(h2, 1); 42 CSS.highlights.set("highlight1", new Highlight(r1, r2)); 43 requestAnimationFrame(() => { 44 container.classList.add('resize'); 45 requestAnimationFrame(() => takeScreenshot()); 46 }); 47 </script> 48 </body>