Skip to content

Instantly share code, notes, and snippets.

@Grawl
Forked from kizu/dabblet.css
Created January 4, 2012 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grawl/1560928 to your computer and use it in GitHub Desktop.
Save Grawl/1560928 to your computer and use it in GitHub Desktop.
Centered heading with rules
/* Centered heading with rules*/
/*General:*/
h1 {
position: relative;
overflow: hidden;
text-align: center;
}
h1:before,
h1:after {
content: "";
position: relative;
display: inline-block;
width: 50%;
height: 2px;
vertical-align: middle;
background: #000;
}
h1:before {
left: -.5em;
margin-left: -50%;
}
h1:after {
left: .5em;
margin-right: -50%;
}
/*Additional*/
h1 {
/*white-space: nowrap; */
/*text-overflow: ellipsis;*/
/*overflow? overflowed header? for what?*/
font: 1.6em/1.1 Georgia;
padding: .2em 0;
}
/*Multiline*/
h1>span {
display: inline-block;
vertical-align: middle;
white-space: normal;
}
/*Works on any background*/
html {
background: #f06;
background: linear-gradient(45deg, #f06, 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, with text-overflow: ellipsis. Since it's too long, the horizontal lines cannot be seen.</p>
{"view":"split-vertical","fontsize":"100","seethrough":"","prefixfree":"1","page":"css"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment