{"id":13,"date":"2008-02-01T16:46:36","date_gmt":"2008-02-01T22:46:36","guid":{"rendered":"http:\/\/cssnewbie.com\/css-rules\/book-style-chapter-intros\/"},"modified":"2008-02-01T16:46:36","modified_gmt":"2008-02-01T22:46:36","slug":"book-style-chapter-intros","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/book-style-chapter-intros\/","title":{"rendered":"Book-style Chapter Introductions Using Pure CSS"},"content":{"rendered":"<p><a href=\"\/example\/book-style-intro\/\"><img src='https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/02\/dropcaps-and-damsels1.gif' alt='' \/><\/a><\/p>\n<p>Do you remember all those wonderful hand-me-down children\u2019s books from your childhood, or perhaps those dusty old tomes you\u2019ve leafed through at a used bookstore recently? I still like looking through old books of Days Gone By. Their typefaces, in particular, give me a warm fuzzy feeling in the far reaches of my tummy. The scripty drop-caps at the beginnings of chapters, and the first line of small caps leading into the first full paragraph, in particular, fill me with all sorts of nostalgia.<\/p>\n<p>So today\u2019s tutorial will show you how easy it is to create book-style chapter (article, whatever) introductions using nothing but pure CSS &mdash; no XHTML was harmed in the making of this tutorial. We\u2019ll use two types of selectors which I haven\u2019t talked about yet here: <em>adjacent sibling<\/em> selectors and <em>pseudo-element<\/em> selectors. I\u2019ll explain each type briefly before we get started.<\/p>\n<p><strong>Adjacent Sibling Selectors<\/strong> are a way of styling an element that appears directly adjacent to another element. So, for example, if you knew that the first paragraph to follow an image in your XHTML was always going to be a caption, and you wanted that styled differently, you could write something like this:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">img + p {\n\tcolor: #999;\n\tfont-style: italic;\n} <\/pre>\n<p>This would turn the paragraph immediately following the image gray and italicize it, all without any extra code in your XHTML.<\/p>\n<p><strong>Pseudo-Element Selectors<\/strong> refer to parts of your XHTML that aren\u2019t technically elements of their own right, but can be easily distinguished from the surrounding code due to their nature. The most common two pseudo-elements (and the two we\u2019re using here) are :first-letter and :first-line.<\/p>\n<p><strong>Creating a Book-Style Introductory Line<\/strong><\/p>\n<p>So what we need to do to create our book-style line is create a drop-cap of the first letter, and the rest of the first line in small caps. And we want to do it without having to resort to classes or IDs to get it done. What we\u2019re assuming in this exercise is that your XHTML is already well-formed \u2013 your articles or chapters always start with a heading tag (I\u2019m using &lt;h4&gt; tags), and you\u2019re using paragraph tags instead of (shudder) line breaks. So here\u2019s how we do it:<\/p>\n<p>You\u2019ll start with some fairly simple XHTML that looks something like this:<\/p>\n<pre lang=\"html4strict\" escaped=\"true\" line=\"1\">&lt;h4&gt;Article Titles for Fun and Profit&lt;\/h4&gt;\n&lt;p&gt;This is our first paragraph. Don\u2019t you think \nthe first line should stand out?&lt;\/p&gt;\n&lt;p&gt;Our second paragraph doesn\u2019t need such \nfancy-pants styling.&lt;\/p&gt;<\/pre>\n<p>And then we\u2019ll use CSS to style the first line of the first paragraph following our 4th level heading:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">h4 + p:first-line {\n\tfont-variant: small-caps; \n\tfont-size: 1.1em;\n}<\/pre>\n<p>This gives us a small-capped line that is slightly larger than the rest of the surrounding text. Now, all we need to do is create our drop cap:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">h4 + p:first-letter {\n\tfloat: left;\n\tfont-size: 2.5em; \n\tfont-weight: bold; \n\tfont-family: \"Monotype Corsiva\", \n\t\"Apple Chancery\", fantasy; \n\tmargin: 5px 5px 5px 0;\n} <\/pre>\n<p>Here, I\u2019ve floated the letter to the left (which causes the rest of the text to flow around it), increased its size, made it boldface, set it in a scripty font (you could chose any font here, but I was going for a bookish look), and added a bit of a margin to make sure there isn\u2019t any overlap.<\/p>\n<p class=\"pullquote\">We\u2019ve managed to create an introductory line without a single byte of XHTML.<\/p>\n<p>And that\u2019s all there is to it! <a href=\"\/example\/book-style-intro\/\">You can see a finished example here.<\/a> We\u2019ve managed to create an old-school book-style introductory line without adding a <em>single byte<\/em> of XHTML. This is a quick and easy way to add some visual appeal to your articles. It could even make for an interesting addition to a print style sheet, adding a bit of classic authenticity.<\/p>\n<p>Now, I have one caveat: this does not work in IE6. But the text simply degrades nicely into an otherwise unaffected first line. No harm, no foul.<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<\/p>\n<p>Do you remember all those wonderful hand-me-down children\u2019s books from your childhood, or perhaps those dusty old tomes you\u2019ve leafed through at a used bookstore recently? I still like looking through old books of Days Gone By. Their typefaces, in [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/book-style-chapter-intros\/\" title=\"Click to read 'Book-style Chapter Introductions Using Pure CSS'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[165,173],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/13"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}