I'd like to recreate this horizontal rule:
I have the double lines, but I'm not sure how to go about getting some kind of a character or image in the center. I'm thinking I might be able to use :before and :after, but I don't know how to utilize them in this case. For the sake of answering the question, let's just try and get the center character to be a character. I'll figure out the image/icon later.
Ideas? Here's my code for the lines:
hr {
display:block;
height:1px;
border:0;
border-top:1px solid #444;
border-bottom:1px solid #444;
margin:25px 0px;
}
Since you have some css already might aswell give it a background image and a height:
It's goofy, but you could try to do two half-width HRs with non-breaking space, and the image between them.
where there's no spacing or line breaks between the tags.
Here is what I believe to be the most responsive, lightweight and modern version for when the symbol isn't a font.
Snippet
Here's a screenshot of what I was able to produce. See it in action at jsfiddle.net.
And here is the CSS:
The section sign
To add the section sign, you can use generated content with either
:before
or:after
. The remaining tricky parts are horizontal centering, vertical centering, and knocking out the borders.Horizontal centering
Horizontal centering is as simple as adding
text-align: center
to thehr
and making sure the generated content isdisplay: inline
.Vertical centering
Vertical centering requires a little knowledge of inline rendering. The vertical space consumed by a line of text is determined by
line-height
. Even if theline-height
is much smaller than the size of the rendered character, the character is still displayed full size, but the space it takes up is dictated by theline-height
. Usingline-height: 1px
achieves the vertical centering.Knocking out the borders
Finally, the only way I know of to knock out the borders behind the section sign is to cover them up with another color. In this case, we use the same background color as is on the rest of the document so it seems to blend in. Set an appropriate
background-color
and then use left and rightpadding
to control how much space is to either side of the section sign.1px gap between the borders
You'll also notice that I'm setting
box-sizing: content-box
. This is to ensure that the gap between the borders is 1px. (An alternative but equivalent set up would bebox-sizing: border-box; height: 3px;
.)Opera rendering bug
@cimmanon pointed out some Opera rendering bugs, so I decided to degrade gracefully and not show the section sign. I think showing just the lines still looks very tidy and professional. If you really want to get this working in Opera, you could use different markup like
<div class="hr"></div>
(and of course update the CSS to match).