{"id":2168,"date":"2011-09-27T16:42:52","date_gmt":"2011-09-27T23:42:52","guid":{"rendered":"http:\/\/www.eaf.net\/mvp\/?p=2168"},"modified":"2013-12-14T20:08:58","modified_gmt":"2013-12-15T04:08:58","slug":"justify-a-headline-with-css","status":"publish","type":"post","link":"https:\/\/www.eaf.net\/mvp\/2011\/justify-a-headline-with-css\/","title":{"rendered":"Justify a Headline With CSS"},"content":{"rendered":"<p>So you want your headline to run the width of the body text.<\/p>\n<p>That seems easy enough to do. Just use the <i>text-align:justify<\/i> CSS property on your <i>H1<\/i>. Like this, for instance: <!--more--><\/p>\n<h2 style=\"text-align:justify; font-size:20px; color:red\">How to Justify a Headline With CSS<\/h2>\n<p><i>Ooooops!<\/i> \ud83d\ude2f What went wrong?!?! \ud83d\ude25<\/p>\n<p>Well, justification is used for multiple lines of text&#8230;with the last line being left-justified rather than stretched out like the others.<\/p>\n<p>A headline is&#8230;well&#8230;a single line. And it gets the same treatment as the last line of a block of text. Thus, no justification.<\/p>\n<p><b>So what to do to achieve a fully-justified headline?<\/b><\/p>\n<p>Ben Clay came up with a slick solution he christened <i>Ben Justification<\/i>. I have tinkered with Ben&#8217;s work plus expanded it with a little SEO bonus.<\/p>\n<p>First, here&#8217;s the CSS:<\/p>\n<pre>div.headline {\r\n  height: 30px;\r\n  display: block;\r\n  overflow: hidden;\r\n}\r\n\r\nh1.headline {\r\n  font-size: 20px;\r\n  text-align: justify;\r\n  width: 100%;\r\n  display: block;\r\n}\r\n\r\nspan.headline {\r\n  font-size: 1px;\r\n  word-spacing: 1000px;\r\n}\r\n<\/pre>\n<p>And then the HTML:<\/p>\n<pre style=\"width:95%\">&lt;div class=\"headline\"&gt;\r\n&lt;h1 class=\"headline\"&gt;\r\nHow to Justify a Headline With CSS\r\n&lt;span class=\"headline\"&gt; Tweak a single line into justifying &lt;\/span&gt;\r\n&lt;\/h1&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>Will it work this time? Well, let&#8217;s take out the line breaks in the above HTML so that&#8217;s all run together and we&#8217;ll see&#8230;<\/p>\n<div style=\"height:30px; display:block; overflow:hidden\">\n<h2 style=\"color:red; font-size:20px; text-align:justify; width:100%; display:block\">How to Justify a Headline With CSS<span style=\"font-size:1px; word-spacing:1000px\"> Tweak a single line into justifying <\/span><\/h2>\n<\/div>\n<p><i>It worked!<\/i><\/p>\n<p>Besides allowing you to justify a single line of text (such as a headline), this includes a browser-hidden-but-seo-visible line (or more?) that says, in this case, <i>&#8220;Tweak a single line into justifying&#8221;<\/i>!<\/p>\n<p>And all it takes to achieve this SEO-enhanced headline justification is only a div, an h1, and a span.<\/p>\n<p>I call this <b>Ben Justification, Markified<\/b>.<\/p>\n<p>Pretty catchy, eh? \ud83d\ude44<\/p>\n<p>Confession: I only tested this in Firefox 6.0.2 and IE 7.<\/p>\n<p>Additional reading on the subject of CSS:<\/p>\n<ul style=\"margin-top:-1.2em\">\n<li><a class=\"amazon\" href=\"http:\/\/www.amazon.com\/CSS-and-Documents\/dp\/B008RBQHTW?tag=markroth-ac-20\" title=\"CSS and Documents by Eric Meyer | Amazon\">CSS and Documents<\/a><\/li>\n<li><a class=\"amazon\" href=\"http:\/\/www.amazon.com\/HTML-CSS-Design-Build-Websites\/dp\/1118008189?tag=markroth-ac-20\" title=\"HTML and CSS: Design and Build Websites by Jon Duckett | Amazon\">HTML and CSS: Design and Build Websites<\/a><\/li>\n<li><a class=\"amazon\" href=\"http:\/\/www.amazon.com\/CSS3-The-Missing-Manual\/dp\/B00APOSIEQ?tag=markroth-ac-20\" title=\"CSS3: The Missing Manual by David McFarland| Amazon\">CSS3: The Missing Manual<\/a><\/li>\n<li><a class=\"amazon\" href=\"http:\/\/www.amazon.com\/Learning-Web-Design-Beginners-JavaScript-ebook\/dp\/B00ANW18T2?tag=markroth-ac-20\" title=\"Learning Web Design: A Beginner's Guide | Amazon\">Learning Web Design: A Beginner&#8217;s Guide to HTML, CSS, JavaScript, and Web Graphics<\/a><\/li>\n<\/ul>\n<p>HT: <a href=\"http:\/\/www.evolutioncomputing.co.uk\/technical-1001.html\" title=\"Ben Justification\">Ben Clay<\/a> via <a href=\"http:\/\/webdesign.about.com\/b\/2008\/03\/21\/reader-question-how-to-justify-a-1-line-headline.htm\" title=\"How to Justify a One-Line Headline\">Jennifer Kyrnin<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>How to do it with only a div, an H1, and a span.<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[13],"tags":[969,909],"class_list":["post-2168","post","type-post","status-publish","format-standard","hentry","category-tech-stuff","tag-code","tag-tips"],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/prJUJ-yY","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/posts\/2168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/comments?post=2168"}],"version-history":[{"count":0,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/posts\/2168\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/media?parent=2168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/categories?post=2168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/tags?post=2168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}