I have found this particular solution to be the most effective for me in the past. You can view an example here. Using ::before and ::after pseudo classes, the code generates lines and then utilizes display:table to ensure the box adjusts to its content (in this case, h2 tags are used in the example). Typically, designs like this are centered, so I added margin: 1em auto;
By doing it this way, there is no need to add any extra HTML markup. I hope this explanation helps.
h2{
display:table;
margin: 1em auto;
}
h2:before, h2:after{
content:"";
display: block;
border-top: 1px solid #ccc;
width: 65px;
margin-top:.5em;
}
h2:before{
float: left;
margin-right:3px;
}
h2:after{
float:right;
margin-left:3px;
}