Skip to content

Instantly share code, notes, and snippets.

@joshuadavidnelson
Created September 5, 2015 05:24
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 joshuadavidnelson/420f0ff79aa3025f87c1 to your computer and use it in GitHub Desktop.
Save joshuadavidnelson/420f0ff79aa3025f87c1 to your computer and use it in GitHub Desktop.
Add line-on-side headers. Fallback for non-javascript browsers is no lines.
jQuery(function( $ ){
// Sets the horizontal location of the lines
$(document).ready(function () {
var entryHeaderWidth = $('.entry-title').width();
var titleWidth = $('.entry-title .title').width();
$('.entry-title span.before').css("right", entryHeaderWidth/2+titleWidth/2 );
$('.entry-title span.after').css("left", entryHeaderWidth/2+titleWidth/2 );
});
});
<h1 class="entry-title"><span class="before"></span><span class="title">%s</span><span class="after"></span></h1>
<!-- Optionally: add a .wrap class around all of it and add a width, then overflow: hidden -->
.entry-title {
text-align: center;
display: inline-block;
margin: 0 auto 0 auto;
position: relative;
width: 100%;
span.before,
span.after {
content: "";
position: absolute;
border-bottom: 5px solid #000; // This is the line on each side, style as you like
top: 50%; // center it vertically
transform: translateY(-50%); // center it vertically
width: 100%;
}
span.before {
right: 100%;
margin-right: 15px; // space between line and text
}
span.after {
left: 100%;
margin-left: 15px; // space between line and text
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment