Last active
March 30, 2017 14:39
-
-
Save maxnordlund/7c99114d15d7d067c3ebe71656c68b1f to your computer and use it in GitHub Desktop.
Pure CSS for `hr` element with caption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$size: 1rem; | |
$background: white; | |
hr[title] { | |
line-height: 0; | |
&::after { | |
background: $background; | |
content: attr(title); | |
// Leaving width on auto allows it to be adjusted according to the content | |
// but we need to specify the height for the positioning to work | |
height: $size; | |
line-height: $size; | |
// Give it a bit of breathing room | |
padding: 0 $size; | |
// Horizontally center it | |
display: table; | |
margin: 0 auto; | |
// Vertically center it above the ruler | |
position: relative; | |
top: -($size / 2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just specify the caption text with the
title
attribute, like so:Will render a horizontal ruler, aka a line, with the text "OR" in the center.
In pure css that becomes: