How to get Line-On-Sides Headers?
The post mockup was this:
I coded up one way to do it which works, but isn’t quite perfect. I figured I’d post it here and you all could chime in with better ways if you can think of them.
If the background was a solid color, this would be fairly easy. Apply the lined background to the subhead and center a span in the middle with a bit of padding and a background color to match the solid background. We don’t have a solid background color here. Perhaps some trickery using the same background image but fixing the background position would work, but I didn’t go there.
Instead, I used the ::before and ::after pseudo elements to create the left and right set of lines. The text is still in a span, which is relatively positioned. The right set is a pseudo element on that span which starts 100% from the left with a bit of margin to push it away, and vice versa for the left set. Both are of a fixed height and use border-top and border-bottom to create the lines. Thus no backgrounds are used and the insides of everything is transparent.
The length of the lines is long enough to always break out of the parent container, and they are cut off by hidden overflow on that parent.
CSS
.fancy {
line-height: 0.5;
text-align: center;
}
.fancy span {
display: inline-block;
position: relative;
}
.fancy span:before,
.fancy span:after {
content: "";
position: absolute;
height: 5px;
border-bottom: 1px solid white;
border-top: 1px solid white;
top: 0;
width: 600px;
}
.fancy span:before {
right: 100%;
margin-right: 15px;
}
.fancy span:after {
left: 100%;
margin-left: 15px;
}
HTML
<article>
<h1>Main Title</h1>
<p class="subtitle fancy"><span>A fancy subtitle</span></p>
<div class="copy">
<p>Bacon ipsum dolor sit amet pancetta meatloaf eiusmod laborum commodo officia ex exercitation bacon. Sunt magna duis ex prosciutto nostrud. Tri-tip ball tip sausage spare ribs sirloin sunt officia anim magna eiusmod turducken sint velit meatball ham hock. Exercitation culpa pork chop rump, short loin meatball ut aute tenderloin.</p>
<p>Cillum pariatur ground round filet mignon capicola ad ham id doner sirloin beef ribs qui mollit pork chop. Laboris bacon officia tenderloin tempor, tongue excepteur tail occaecat meatloaf consectetur ham hock consequat ut. Frankfurter jerky enim irure salami aliqua. In pork loin meatball, ut ad in nisi turkey turducken mollit.</p>
<p>Filet mignon capicola aute short loin pork belly qui ball tip spare ribs do short ribs sint. Commodo dolore rump nostrud ball tip. Veniam in hamburger tail, sunt culpa beef ribs ham hock irure. Ut bresaola flank consectetur pastrami sirloin short ribs meatball pork officia sausage in doner pork loin sed. Pastrami duis non pork loin magna, pig quis bresaola. Esse t-bone laborum, ex turkey proident flank aliquip occaecat qui sint non eiusmod strip steak spare ribs. Anim kielbasa pork chop id ut dolore commodo prosciutto doner magna.</p>
</div>
</article>
<article>
<h1>
<span class="embiggen">Love</span>
<div class="fancy amp"><span>&</span></div>
Marriage
</h1>
<div class="copy">
<p>Go together like a horse and carridge. Cillum pariatur ground round filet mignon capicola ad ham id doner sirloin beef ribs qui mollit pork chop. Laboris bacon officia tenderloin tempor, tongue excepteur tail occaecat meatloaf consectetur ham hock consequat ut. Frankfurter jerky enim irure salami aliqua. In pork loin meatball, ut ad in nisi turkey turducken mollit.</p>
<p>Filet mignon capicola aute short loin pork belly qui ball tip spare ribs do short ribs sint. Commodo dolore rump nostrud ball tip. Veniam in hamburger tail, sunt culpa beef ribs ham hock irure. Ut bresaola flank consectetur pastrami sirloin short ribs meatball pork officia sausage in doner pork loin sed. Pastrami duis non pork loin magna, pig quis bresaola. Esse t-bone laborum, ex turkey proident flank aliquip occaecat qui sint non eiusmod strip steak spare ribs. Anim kielbasa pork chop id ut dolore commodo prosciutto doner magna.</p>
</div>
</article>
CSS:
@import url(http://fonts.googleapis.com/css?family=Cinzel+Decorative:400,900);
body {
font-family: 'Cinzel Decorative', cursive;
background: url(http://s.cdpn.io/3/blurry-blue.jpg);
background-size: cover;
color: white;
}
h1 {
font-size: 3em;
text-align: center;
}
.embiggen {
font-size: 4em;
text-shadow: 0 0 40px #ffbab3;
}
article {
max-width: 600px;
overflow: hidden;
margin: 0 auto 50px;
}
.subtitle {
margin: 0 0 2em 0;
}
.fancy {
line-height: 0.5;
text-align: center;
}
.fancy span {
display: inline-block;
position: relative;
}
.fancy span:before,
.fancy span:after {
content: "";
position: absolute;
height: 5px;
border-bottom: 1px solid white;
border-top: 1px solid white;
top: 0;
width: 600px;
}
.fancy span:before {
right: 100%;
margin-right: 15px;
}
.fancy span:after {
left: 100%;
margin-left: 15px;
}
.amp {
margin: 0 0 0.25em 0;
}
.amp span {
font-size: 0.7em;
}
.copy {
font: 1em Georgia, Serif;
text-align: justify;
-moz-column-count: 2;
-moz-column-gap: 20px;
-webkit-column-count: 2;
-webkit-column-gap: 20px;
}
.copy p {
margin: 0 0 1em 0;
}
CSS
@import url(http://fonts.googleapis.com/css?family=Cinzel+Decorative:400,900);
body {
font-family: 'Cinzel Decorative', cursive;
background: url(http://s.cdpn.io/3/blurry-blue.jpg);
background-size: cover;
color: white;
}
h1 {
font-size: 3em;
text-align: center;
}
.embiggen {
font-size: 4em;
text-shadow: 0 0 40px #ffbab3;
}
article {
max-width: 600px;
overflow: hidden;
margin: 0 auto 50px;
}
.subtitle {
margin: 0 0 2em 0;
}
.fancy {
line-height: 0.5;
text-align: center;
}
.fancy span {
display: inline-block;
position: relative;
}
.fancy span:before,
.fancy span:after {
content: "";
position: absolute;
height: 5px;
border-bottom: 1px solid white;
border-top: 1px solid white;
top: 0;
width: 600px;
}
.fancy span:before {
right: 100%;
margin-right: 15px;
}
.fancy span:after {
left: 100%;
margin-left: 15px;
}
.amp {
margin: 0 0 0.25em 0;
}
.amp span {
font-size: 0.7em;
}
.copy {
font: 1em Georgia, Serif;
text-align: justify;
-moz-column-count: 2;
-moz-column-gap: 20px;
-webkit-column-count: 2;
-webkit-column-gap: 20px;
}
.copy p {
margin: 0 0 1em 0;
}