I looked at a bunch of solutions to this problem, and I really wanted something simple. Why not just use :before
and :after
to embed some content in the header in which you want to have a horizontal rule / line. In my CSS below, I selected EM DASH ( unicode \2014
) for the horizontal header line. When creating a larger horizontal line and depending on your font, you need to subtract the distance between the letters from several EM DASHes. Finally, you can add some additions to the head and tail of the EM DASH so that it does not click on your title text.
Here is some CSS, header-1 is very simple, header-2 has a longer line (see the action https://jsfiddle.net/pyxkh3jz/ ):
h1:before, h1:after { content:"\2014"; } h2:before, h2:after { content:"\2014\2014"; letter-spacing: -6px; } h2:before { padding-right: 15px; } h2:after { padding-left: 15px; }
Did not check browser compatibility; but this is not radical CSS, so it should work for some or most of you. The lines and their length correspond to my use case.
This idea can probably be improved by other fans ... on it!
source share