tailwind2-9 Exercise 3: Logical Properties, RTL and Print ============================================================== Setup: a folder with npm install tailwindcss @tailwindcss/cli and in.css containing @import "tailwindcss"; Build with node node_modules/@tailwindcss/cli/dist/index.mjs -i in.css -o out.css The scripts below use my own small DevTools driver (cdp.mjs: real key presses and clicks, Emulation.setEmulatedMedia, raw send for Accessibility and Page.printToPDF). If you do not have it, the same checks can be made by hand in Chrome DevTools: Rendering panel (emulate prefers-reduced-motion, prefers-contrast, forced-colors, print), Elements > Accessibility tab (computed name), and File > Print. --- logical and rtl section of page.html ---
logical
physical
rtl/ltr
start-0end-0
--- r5.mjs --- import { withPage } from '../../c4/cdp.mjs'; await withPage('file:///C:/lwdj/tw2/c9/a/page.html', async (p) => { const box = async (id) => ['margin-left','margin-right','padding-left','padding-right','border-left-width','border-right-width','text-align'].map(async k=> k.replace('-width','').replace('margin-','m-').replace('padding-','p-')+'='+await p.css('#'+id,k)); const show = async (label,id)=> console.log(label.padEnd(26), (await Promise.all(await box(id))).join(' ')); await show('LTR logical (l1)','l1'); await show('LTR physical (l2)','l2'); console.log('LTR rtl/ltr variants (l3) bg', await p.css('#l3','background-color'), '| margin-left', await p.css('#l3','margin-left')); console.log('LTR start-0 left', await p.ev(`Math.round(document.querySelector('#l4 span:nth-child(1)').getBoundingClientRect().left)`), '| end-0 left', await p.ev(`Math.round(document.querySelector('#l4 span:nth-child(2)').getBoundingClientRect().left)`)); await p.ev(`document.getElementById('logical').dir='rtl'`); await show('RTL logical (l1)','l1'); await show('RTL physical (l2)','l2'); console.log('RTL rtl/ltr variants (l3) bg', await p.css('#l3','background-color'), '| margin-left', await p.css('#l3','margin-left'), '| margin-right', await p.css('#l3','margin-right')); console.log('RTL start-0 left', await p.ev(`Math.round(document.querySelector('#l4 span:nth-child(1)').getBoundingClientRect().left)`), '| end-0 left', await p.ev(`Math.round(document.querySelector('#l4 span:nth-child(2)').getBoundingClientRect().left)`)); console.log('PRINT screen: p1 display', await p.css('#p1','display'), '| p2', await p.css('#p2','display'), '| p3 bg', await p.css('#p3','background-color')); await p.media([], 'print'); console.log('PRINT print : p1 display', await p.css('#p1','display'), '| p2', await p.css('#p2','display'), '| p3 bg', await p.css('#p3','background-color'), '| p3 color', await p.css('#p3','color')); }); Results LTR logical (l1) m-left=16px m-right=32px p-left=8px p-right=24px border-left=4px border-right=0px text-align=start LTR physical (l2) m-left=16px m-right=32px p-left=8px p-right=24px border-left=4px border-right=0px text-align=left LTR l3 bg green, margin-left 0px ; start-0 span left 16, end-0 span left 826 RTL logical (l1) m-left=32px m-right=16px p-left=24px p-right=8px border-left=0px border-right=4px text-align=start RTL physical (l2) unchanged from LTR RTL l3 bg red (rtl:bg-red-500), margin-right 40px (rtl:ms-10) ; start-0 span left 822, end-0 span left 16 PRINT screen: nav display block, "only in print" display none, p3 yellow ; print media: nav none, "only in print" block, p3 rgb(255,255,255) with text rgb(0,0,0) Logical-axis utilities built (b/p.html, 4.3.3): pbs-4 pbe-1 mbs-3 mbe-2 inline-4 block-8 min-inline-2 max-block-10 border-bs-2 inset-s-1 inset-bs-0 start-0 border-s-2 ps-2 all produce a rule; pis-2, pie-3, mis-1, mie-4 produce nothing. --- print pages: a.html (nav, three h-80 sections), b.html (nav has print:hidden), c.html (b + break-before-page on sections two and three) ---
one
two
three
b.html: the nav line becomes