custom-highlight-dynamic-container-metrics-004.html (1458B)
1 <!DOCTYPE html> 2 <meta charset="UTF-8"> 3 <title>CSS Highlight API Test: Highlights using 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="a highlight on a container itself renders at the correct size when the container changes"> 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 .wrapper::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="h1" class="wrapper">With container size</div> 32 <div id="h2">Should be no highlight</div> 33 <script> 34 let r1 = new Range(); 35 r1.setStart(h1, 0); 36 r1.setEnd(h1, 1); 37 let r2 = new Range(); 38 r2.setStart(h2, 0); 39 r2.setEnd(h2, 1); 40 CSS.highlights.set("highlight1", new Highlight(r1, r2)); 41 requestAnimationFrame(() => { 42 h1.classList.add('resize'); 43 requestAnimationFrame(() => takeScreenshot()); 44 }); 45 </script> 46 </body> 47 </html>