HEELPBOOK - CSS – How to implement simple Drop-Cap ######################## You can’t have failed to notice the drop-cap effect we’re using in the new blogs design, as well as the first-line uppercasing that most browsers display (except Safari, for reasons I’ll explain in a moment). There are quite a few hacky methods for implementing this effect, but the cleanest and most maintainable is pure CSS, using the :first-letter and :first-line pseudo-classes. This approach means no additional markup, no images, and no need to know about the content — whatever the first letter and first line are, they’ll have the effect applied. Here’s the CSS that makes it happen: #post-content > p:first-child:first-line, #post-content > .ad:first-child + p:first-line { text-transform:uppercase; position:relative; font-size:0.95em; letter-spacing:1px; } #post-content > p:first-child:first-letter, #post-content > .ad:first-child + p:first-letter { letter-spacing:0; text-transform:uppercase; color:#628fbe; font-family:times,serif; font-size:3.5em; float:left; margin:0.13em 0.2em 0 0; line-height:0.7; } You’ll notice how there are two different selectors attempting to apply the effect, to the first paragraph inside the content area. It needed to be flexible enough to allow for the presence, or lack, of an ad immediately before the paragraph, marked-up as
. So ideally I would have used :first-of-type, which selects the first element of a specified type within its parent context: #post-content > p:first-of-type:first-line { } #post-content > p:first-of-type:first-letter { } But that’s not as widely supported; the selectors we’re using mean we get support for IE8 that we otherwise wouldn’t. For the first-line uppercasing we unfortunately don’t get support for Safari. It’s not because of the selectors — it supports all the examples shown here, and does apply other properties within those rules — it just doesn’t apply the text-transform. This is something I’ve noticed in a number of different situations, where Safari doesn’t apply the transform, for no readily-apparent reason. I’ve seen it fail to apply to an element where it worked for a corresponding