4 ms·
Not Your Typical Horizontal Rules
- pseudosavant 6y agoThis is a great exploration of how to use SVG on the web. It is a very under-utilized technology. One thing that would add to this post is to point out that you can define an SVG once in a document and then reference it everywhere else. That way you aren't inlining the actual SVG markup over and over and over. 1. Place your SVG inline anywhere in the document. I usually put all of them in a `<div>` I do `display: none` on. 2. Make sure you assigned each SVG an ID: `<svg id="foobar"><!-- SVG markup --></svg>` 3. Reference that SVG anywhere in your document using `<svg><use xlink:href='#foobar'></svg>` I use it extensively in a Github project (shameless plug) I've been working on lately. https://github.com/pseudosavant/player.html/blob/master/src/player.html#L682 https://github.com/pseudosavant/player.html/blob/master/src/... Edit: The author does link to her great post digging into the details of using `<use>`, but it didn't seem prominent enough that people would check it out. https://tympanus.net/codrops/2015/07/16/styling-svg-use-content-css/ https://tympanus.net/codrops/2015/07/16/styling-svg-use-cont...
- wavefunction 6y agoNice tip, love to learn little things like this.
- gwern 6y agoHorizontal rules are a fun element to play with. On my website, I wrote a Pandoc compile pass to count rules inside a document and number them modulo 3, so they cycle: stars / moon / sun https://www.gwern.net/Lorem#horizontal-rulers https://www.gwern.net/Lorem#horizontal-rulers Each ruler gets a class for being a 1th, 2th, or 3th ruler. (You can't do this in pure CSS easily because the rulers could be nested at any depth so the usual :nth counters don't work. You could do it in JS, of course, but I try to minimize use of that.) Why? Because the icons are really nice-looking, especially in dark mode, compared to a boring line, and I felt the astronomical touch added some class, combined with the moons in the footer.
- rgovostes 6y agoThey don’t seem to work for me on iOS Safari.
- jfk13 6y agoNor on desktop (macOS) Safari.
- gwern 6y agoNot work in what sense? You see default rulers but not fancy SVG icons? You see no decoration at all? What? (HNers know how useless "it doesn't work" is as feedback when there are so many ways for something to not work, and when it obviously works fine for most people who use it and the developers responding to the feedback, or it would've been fixed already.)
- rgovostes 6y agoYes I suppose I could be more descriptive. No ruler appears at all. But since I do not know the root cause, you are going to have to get ahold of Safari to debug it anyway. https://i.imgur.com/2MBBo3c.png https://i.imgur.com/2MBBo3c.png
- gwern 6y agoAh. Turns out Obormot wasn't using Safari at all, which is why he hadn't noticed. I've never owned any Apple devices at all, so I can't test either. It turns out Safari (still, thanks Apple!) has poor flexbox support so the SVGs just vanish... We've fixed it, we think.
- lupire 6y agoDoes it work for you on Safari?
- _Microft 6y agoHmm, can't you use CSS counters that get incremented on every rule and apply a custom, cyclic counter-style to them that contains the symbols you would like? Counters work independently of the depth of the element in the tree. Edit: like that: (sorry in advance, mobile users) @counter-style rulestyle { symbols: "*" ")" "+"; /* Symbols go here, images work too. */ system: cyclic; } body { /* Initialize counter somewhere. */ counter-reset: rules; } hr { /* Style <hr/> as wanted. */ border: none; text-align: center; } hr:before { counter-increment: rules; content: counter(rules, rulestyle); } Edit 2: according to caniuse.com this seems to be only properly supported in Firefox so far.
- ghusbands 6y agoI haven't tested it, but I think this would not work well with text-mode browsers (like lynx), as they likely would not recognise the role attribute. Possibly, for them, there should also be a concealed actual hr node.
- basilgohar 6y agoThe author is using SVG to style actual HR elements.
- lupire 6y agoKeep (re-)reading to the end.
- lupire 6y agoThere are two main "its" in the article. One of them (SVG tag) might not work in old browsers that don't support modern standards. "Text mode" isn't the issue, as screen readers are also "text mode".