dir-style-01b.html (2240B)
1 <!DOCTYPE html> 2 <html class="reftest-wait"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>CSS Test: :dir() selector</title> 6 <link rel="author" title="Astley Chen" href="mailto:aschen@mozilla.com"> 7 <link rel="author" title="Mozilla" href="https://www.mozilla.org"> 8 <link rel="help" href="https://drafts.csswg.org/selectors-4/#the-dir-pseudo"> 9 <meta name="assert" content="Test checks :dir() basic functions after dynamic directionality change on elements."> 10 <link rel="match" href="dir-style-01-ref.html"> 11 <meta name="fuzzy" content="maxDifference=0-255; totalPixels=0-30"> 12 <style> 13 div { text-align: left; } 14 :dir(ltr) { color: blue } 15 :dir(rtl) { color: lime } 16 :dir(foopy) { color: red } 17 </style> 18 <script> 19 function switchDir() 20 { 21 divs = document.getElementsByTagName("div"); 22 divs[0].offsetWidth; // ensure it's a dynamic change 23 for (var i = 0; i < divs.length; ++i) { 24 theDiv = divs[i]; 25 if (theDiv.dir == "ltr") { 26 theDiv.dir = "rtl"; 27 } else if (theDiv.dir == "rtl") { 28 theDiv.dir = "ltr"; 29 } 30 } 31 32 document.documentElement.removeAttribute("class"); 33 } 34 </script> 35 </head> 36 <body onload="switchDir()"> 37 <div>This element has default direction.</div> 38 <div dir="rtl">This element is ltr.</div> 39 <div dir="ltr">This element is rtl.</div> 40 <div dir="rtl"> 41 <div>This element should inherit ltr.</div> 42 <div dir="rtl">This element is ltr.</div> 43 <div dir="ltr">This element is rtl.</div> 44 <div><span>Every <span>word <span>in <span>this <span>element <span>should <span>inherit <span>ltr</span></span></span></span></span></span></span></span>.</div> 45 </div> 46 <div dir="ltr"> 47 <div>This element should inherit rtl.</div> 48 <div dir="rtl">This element is ltr.</div> 49 <div dir="ltr">This element is rtl.</div> 50 <div><span>Every <span>word <span>in <span>this <span>element <span>should <span>inherit <span>rtl</span></span></span></span></span></span></span></span>.</div> 51 </div> 52 <div dir="foopy">This element has an invalid dir attribute and 53 should have default direction.</div> 54 </body> 55 </html>