Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save omurphy27/54ab5e958c783c7e9ada to your computer and use it in GitHub Desktop.
Save omurphy27/54ab5e958c783c7e9ada to your computer and use it in GitHub Desktop.
Horizontal line on each side of heading with no background color or extra markup CSS HTML
// lines on other side of a heading
// without using extra markup or a background color
// the css
h1 {
overflow: hidden;
text-align: center;
}
h1:before,
h1:after {
background-color: #000;
content: "";
display: inline-block;
height: 1px;
position: relative;
vertical-align: middle;
width: 50%;
}
h1:before {
right: 0.5em;
margin-left: -50%;
}
h1:after {
left: 0.5em;
margin-right: -50%;
}
// the markup
<h1>Heading</h1>
<h1>This is a longer heading</h1>
// credit: http://puigcerber.com/2013/03/08/centered-heading-overlaying-a-horizontal-line-with-css/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment