interaction-with-pseudo-elements.html (3796B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>CSS Shadow Parts - Interaction with pseudo-elements</title> 5 <meta href="mailto:fergal@chromium.org" rel="author" title="Fergal Daly"> 6 <link href="http://www.google.com/" rel="author" title="Google"> 7 <link href="https://drafts.csswg.org/css-shadow-parts/" rel="help"> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="support/shadow-helper.js"></script> 11 </head> 12 <body> 13 <style> 14 #c-e::part(before-p)::before { color: green; } 15 #c-e::part(after-p)::after { color: green; } 16 #c-e::part(placeholder-p)::placeholder { color: green; } 17 #c-e::part(selection-p)::selection { color: green; } 18 #c-e::part(first-line-p)::first-line { color: green; } 19 #c-e::part(first-letter-p)::first-letter { color: green; } 20 </style> 21 <script>installCustomElement("custom-element", "custom-element-template");</script> 22 <template id="custom-element-template"> 23 <style> 24 #before-i::before { content: "this text"; color: red; } 25 #after-i::after { content: "this text"; color: red; } 26 #placeholder-i::placeholder { color: red; } 27 #selection-i::selection { color: red; } 28 #first-line-i::first-line { color: red; } 29 #first-letter-i::first-letter { color: red; } 30 </style> 31 <div> 32 The following text should be green: 33 <span id="before-i" part="before-p"></span> 34 </div> 35 <div> 36 The following text should be green: 37 <span id="after-i" part="after-p"></span> 38 </div> 39 <div> 40 The following text should be green: 41 <input id="placeholder-i" part="placeholder-p" placeholder="this text"></input> 42 </div> 43 <div> 44 The selected text should be green: 45 <div id="selection-i" part="selection-p">select some text</div> 46 </div> 47 <div> 48 The following text should be green: 49 <div id="first-line-i" part="first-line-p">this text<br>Not this</div> 50 </div> 51 <div> 52 The first letter should be green: 53 <div id="first-letter-i" part="first-letter-p"><p>this text</p></div> 54 </div> 55 </template> 56 <custom-element id="c-e"></custom-element> 57 <script> 58 "use strict"; 59 const colorGreen = "rgb(0, 128, 0)"; 60 test(function() { 61 const el = getElementByShadowIds(document, ["c-e", "before-i"]); 62 assert_equals(window.getComputedStyle(el, '::before').color, colorGreen); 63 }, "::before in selected host is styled"); 64 test(function() { 65 const el = getElementByShadowIds(document, ["c-e", "after-i"]); 66 assert_equals(window.getComputedStyle(el, '::after').color, colorGreen); 67 }, "::after in selected host is styled"); 68 test(function() { 69 const el = getElementByShadowIds(document, ["c-e", "placeholder-i"]); 70 assert_equals(window.getComputedStyle(el, '::placeholder').color, colorGreen); 71 }, "::placeholder in selected host is styled"); 72 test(function() { 73 const el = getElementByShadowIds(document, ["c-e", "selection-i"]); 74 assert_equals(window.getComputedStyle(el, '::selection').color, colorGreen); 75 }, "::selection in selected host is styled"); 76 test(function() { 77 const el = getElementByShadowIds(document, ["c-e", "first-line-i"]); 78 assert_equals(window.getComputedStyle(el, '::first-line').color, colorGreen); 79 }, "::first-line in selected host is styled"); 80 test(function() { 81 const el = getElementByShadowIds(document, ["c-e", "first-letter-i"]); 82 assert_equals(window.getComputedStyle(el, '::first-letter').color, colorGreen); 83 }, "::first-letter in selected host is styled"); 84 </script> 85 </body> 86 </html>