I'm trying to create an effect that essentially frames a title tag with two line either side that fill the remaining width of the container. I'm trying to create it so that whatever length the title text is, you still get the same effect + amount of spacing. This image better shows what I'm trying to explain:
The closest I've got is by using percentage widths, but if only a small title is used there is lots of remaining space. Usually I would add a background color to a span object within my title tag, but I'm also trying to make it so the effect will work on varied background colors.
Here's a jsfiddle: https://jsfiddle.net/wv9zcuvm/ and some code:
HTML:
<h2><span>Small title</span></h2>
CSS:
h2{
width:100%;
position:relative;
top:0; left: 0;
}
h2:before,
h2:after{
content:"";
display:inline-block;
width:30%;
height:1px;
background-color:red;
position:relative;
top: -10px;
}
h2:before{
left:0;
}
h2:after{
right:0;
}
h2 span{
width:40%;
display:inline-block;
text-align:center;
}
Can anyone suggest how I can achieve what I'm trying to create?