{"id":297824,"date":"2019-10-25T14:53:36","date_gmt":"2019-10-25T21:53:36","guid":{"rendered":"https:\/\/css-tricks.com\/?p=297824"},"modified":"2019-10-25T14:53:36","modified_gmt":"2019-10-25T21:53:36","slug":"bidirectional-horizontal-rules-in-css","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/bidirectional-horizontal-rules-in-css\/","title":{"rendered":"Bidirectional Horizontal Rules in CSS"},"content":{"rendered":"
Say you have a That’s exactly what CSS logical properties<\/a> are meant to address, and Hussein Al Hammad has a nice article<\/a> laying out some use cases, including the blockquote thing I mentioned above.<\/p>\n <\/p>\n By using logical properties, you don’t have to mess around with manually writing selectors including Hussein’s blockquote is a good baby step example for understanding of all this:<\/p>\n \n See the Pen Support is pretty good.<\/p>\n This browser support data is from Caniuse<\/a>, which has more detail. A number indicates that browser supports the feature at that version and up.<\/p><\/div> One thing that threw me off in the article is the term “Horizontal Rules.” First I imagined the We could draw the shorter line with backgrounds that cover different parts of the box model, then use logical properties where the padding applies. This is a pretty unique edge case, but it’s fun to fiddle with:<\/p>\n \n See the Pen <blockquote><\/code> and the design calls for a thick border along the left side. Well, you might not necessarily mean left<\/em> side, but actually mean on the side of the start of the text<\/em>. <\/p>\n
[dir=\"rtl\"]<\/code> or needing to be aware of writing modes and such. The box model stuff (borders, padding, margin…) will adjust where it needs to be.<\/p>\n
blockquote {\r\n \/* Rather than... *\/\r\n border-left: 4px solid #aaa;\r\n padding-left: 1.75rem;\r\n\r\n \/* You'd do... *\/\r\n border-inline-start: 4px solid #aaa;\r\n padding-inline-start: 1.75rem;\r\n}<\/code><\/pre>\n
\n Logical properties demo: blockquote<\/a> by Hussein Al Hammad (@hus_hmd<\/a>)
\n on CodePen<\/a>.<\/span>\n<\/p>\nDesktop<\/h4>
Chrome<\/span><\/th> Firefox<\/span><\/th> IE<\/span><\/th> Edge<\/span><\/th> Safari<\/span><\/th><\/tr><\/thead> 89<\/span><\/td> 66<\/span><\/td> No<\/span><\/td> 89<\/span><\/td> 15<\/span><\/td><\/tr><\/table><\/div> Mobile \/ Tablet<\/h4>
Android Chrome<\/span><\/th> Android Firefox<\/span><\/th> Android<\/span><\/th> iOS Safari<\/span><\/th><\/tr><\/thead> 124<\/span><\/td> 125<\/span><\/td> 124<\/span><\/td> 15.0-15.1<\/span><\/td><\/tr><\/table><\/div><\/div>\n <hr><\/code> element. Then I imagined wanting to reverse the direction of the design with logical properties. Usually an
<hr><\/code> is just a line so horizontal direction doesn’t matter, but let’s say it’s like a shorter<\/em> line along the edge where new lines start after wrapping.<\/p>\n
\n <hr>s that are direction aware kinda<\/a> by Chris Coyier (@chriscoyier<\/a>)
\n on CodePen<\/a>.<\/span>\n<\/p>\n