I am trying to make a decorative heading with horizontal lines either side, similar to http://www.impressivewebs.com/centered-heading-horizontal-line/ but with the following constraints:
I am trying to use CSS only for the solution, although I would consider JavaScript help if it cannot be done with pure CSS.
I have seen a few similar questions on SO, but I don't think that any of the solutions would do quite what I'm looking for.
Here is my own naive attempt (also at http://jsfiddle.net/39qLr/1/). For simplicity I have coloured the "tip" images in red, and the flexible repeating images in yellow. The obvious problem is that the yellow parts are not showing up right now!
HTML:
<div class="heading-container">
<div class="left-tip"></div>
<div class="left-filler"></div>
<h1>Heading Text</h1>
<div class="right-filler"></div>
<div class="right-tip"></div>
</div>
CSS:
.heading-container {
display: table;
width: 100%;
}
.left-tip, .right-tip {
background-color: red;
width: 297px;
display: table-cell;
}
.left-filler, .right-filler {
background-color: yellow;
display: table-cell;
}
h1 {
text-align: center;
display: table-cell;
}
I am very grateful for any guidance!
With help from a colleague, we have managed to get as close as we think is possible:
http://jsfiddle.net/rbCvq/
HTML (same as before):
<div class="heading-container">
<div class="cell left-tip"> </div>
<div class="cell left-filler"> </div>
<h1 class="cell heading-text">Heading Text</h1>
<div class="cell right-filler"> </div>
<div class="cell right-tip"> </div>
</div>
CSS:
.heading-container {
display: table;
width: 100%;
}
.cell
{
display: table-cell;
}
.left-tip, .right-tip {
width: 297px;
background: red;
}
.left-filler, .right-filler {
background: yellow;
}
.heading-text {
width: 1px;
white-space: nowrap;
}
The secret sauce that makes it work seems to be:
white-space: nowrapnbsp; in the empty DIVsOf course this doesn't fulfil my original criteria of making the text wrap onto multiple lines, but I think the overall effect works about as well as we could hope. Also, the markup is a bit heavy on the DIVs, which serve no semantic purpose.
Thank you for all the suggestions, and I hope this is useful to somebody else one day!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With