Skip to content

Instantly share code, notes, and snippets.

@kizu
Created April 26, 2012 19:52
Show Gist options
  • Select an option

  • Save kizu/2502535 to your computer and use it in GitHub Desktop.

Select an option

Save kizu/2502535 to your computer and use it in GitHub Desktop.
Centered heading with rules
/* Centered heading with rules */
h1 {
position: relative;
overflow: hidden;
white-space: nowrap;
text-align: center;
font: 1.6em/1.1 Georgia;
padding: .2em 0;
text-shadow: 0 1px rgba(255,255,255,.6);
}
h1:before,
h1:after {
content: "";
position: relative;
display: inline-block;
width: 50%;
height: 2px;
vertical-align: middle;
background: #000;
background-clip: content-box;
border-bottom: 1px solid rgba(255,255,255,.5);
}
h1:before {
left: -.5em;
margin: 0 0 0 -50%;
}
h1:after {
left: .5em;
margin: 0 -50% 0 0;
}
h1>span {
display: inline-block;
vertical-align: middle;
white-space: normal;
}
/* Works on any background */
html {
background: #f06;
background: linear-gradient(45deg, #f39, yellow);
min-height:100%;
font: 1.3em/1.5 Georgia;
}
<h1>Hello!</h1>
<p>Here are the centered headings with horizontal lines.</p>
<p>They are one-lined by default, but if it needs to be multiline, then you can add an extra span.</p>
<h1><span>Multiline heading<br/>with an extra wrapping span</span></h1>
<h1>Some long, long heading without a wrapping span, so it would be overflown. Some long, long heading without a wrapping span, so it would be overflown. Some long, long heading without a wrapping span, so it would be overflown.</h1>
<p>↑ Here you can see one-lined heading, <del title="FireFox incorrectly shows the ellipsis on the previous items, so I removed them here." style="cursor: help;">with text-overflow: ellipsis.</del> Since it's too long, the horizontal lines cannot be seen.</p>
{"view":"separate","fontsize":"100","seethrough":"","prefixfree":"1","page":"result"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment