Skip to content

Instantly share code, notes, and snippets.

@jcutrell
Created July 19, 2012 13:57
Show Gist options
  • Save jcutrell/3144098 to your computer and use it in GitHub Desktop.
Save jcutrell/3144098 to your computer and use it in GitHub Desktop.
Centered text with letter-spacing fix
// requires jQuery
$("h2").each(function(){
var h2 = $(this);
var t = h2.text();
var last = t.split("")[t.length-1];
var newtext = t.substring(0,t.length-1) + "<span style='letter-spacing:0px;'>" + last + "</span>";
h2.html(newtext);
});
// if h2 has letter-spacing > 0 and text-align:center applied in css, this function will remove the letter spacing on the last letter, which fixes the issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment