Nadj Nadj - 1 year ago 92
CSS Question

How to display a horizontal line before and after a heading in css

I am trying to style a an html heading in css but am not getting the correct result as my jsfiddle shows: .
The following are the html and css codes:


border-bottom: 1px solid #000;
line-height:0.1em; margin:10px 0 20px;
h2 span{
padding:0 10px;

How can I put the horizontal line only before and after the heading and also control the width of the line so that such doesn't occupy the full width of the screen?

Answer Source

There's obviously many ways you can achieve what you're after. But how about something like this?

h1::after {
    display: inline-block;
    content: "";
    border-top: .3rem solid black;
    height: 4rem;
    width: 2rem;
    margin: .5rem;
    transform: translateY(95%);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download