I'm trying to make a horizontal rule with some text in the middle. For example:
----------------------------------- my title here -----------------------------
Is there a way to do that in CSS? Without all the "-" dashes obviously.
I'm trying to make a horizontal rule with some text in the middle. For example:
----------------------------------- my title here -----------------------------
Is there a way to do that in CSS? Without all the "-" dashes obviously.
I use a table layout to fill the sides dynamically and 0-height, absolute-position divs for dynamic vertical positioning:
https://jsfiddle.net/eq5gz5xL/18/
I found that a little below true center looks best with text; this can be adjusted where the
55%
is (taller height makes the bar lower). The appearance of the line can be changed where theborder-bottom
is.HTML:
CSS:
I am not too sure, but you could try using a horizontal rule and pushing the text above its top margin. You will need a fixed width on your paragraph tag and a background too. It's a little hacky and I don't know if it will work on all browsers, and you need to set the negative margin based on the size of the font. Works on chrome though.
After trying different solutions, I have come with one valid for different text widths, any possible background and without adding extra markup.
I tested it in IE8, IE9, Firefox and Chrome. You can check it here http://jsfiddle.net/Puigcerber/vLwDf/1/
For me this solution works perfectly fine...
HTML
<h2 class="strikethough"><span>Testing Text</span></h2>
CSS
Give the span a padding to make more space between the text and the line.
Example: http://jsfiddle.net/tUGrf/