:first-letter — A Better Drop Cap

I’m not much for initial drop caps but if the design you’re building uses them, personal preference doesn’t matter. I’ve often seen drop-caps implemented by wrapping the first letter of the paragraph in a span tag and giving it a class of drop-cap or something similar. If the design changes though and doesn’t include drop-caps any longer, having all of the extra markup in your content doesn’t really make sense anymore.

A better, cleaner way to go about it is to use the pseudo elements built into CSS2. There are four useful pseudo elements, :first-line, :first-letter, :before, and :after. The before and after elements are some of my favorites but, of course, no version of Internet Explorer supports them. Amazingly enough, IE does support the first-line and first-letter pseudo elements.

Assuming you would only want a drop cap on the first paragraph, give your first paragraph a class of drop-cap, unless you want all your paragraphs to have them. Then, include the following in your CSS:

p.drop-cap:first-letter {
   float: left;
   font-size: 3em;
   line-height: 1em;
   padding-right: 0.125em;
}
Demo:  

The first letter of this should be styled. Sed accumsan ipsum vel dui. In hac habitasse platea dictumst. Nulla facilisi. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla malesuada consectetuer elit. Sed vehicula semper arcu.

Posted Friday, August 31st, 2007 • No comments »
Topics: Web Development

Sizing Text with CSS / Overriding Browser Defaults

A friend of mine was talking with me about sizing text for the Web and how there are seemingly thousands of articles out there but few truly useful solutions. I’ve recently come across one that I feel ties together some very reasonable approaches, including the idea of establishing an initial stylesheet that overrides browser defaults for things like heading padding, margins, etc. It’s definitely worth a read!

CSS techniques I use all the time –The Montoya Herald

Posted Wednesday, April 11th, 2007 • Comments Off
Topics: Web Development

Some Thoughts on Ajax and Anchors

I’m going through some little mini-demos I did for Ajax testing and I’m coming up with some …guidelines of sorts. On the other hand, this might just be a string of mildly random thoughts on the topic. Well, whatever it is, here’s what I’m thinking: (more…)

Posted Thursday, October 19th, 2006 • One comment »
Topics: Web Development

The Trouble with Em ‘n En

I actually came across this article, a while ago and I’m just now getting around to posting about it. It’s an excellent article and if you’re a person that is passionate about grammar and punctuation, you really have to read The Trouble With EM ‘n EN (and Other Shady Characters).

Posted Thursday, March 16th, 2006 • No comments »
Topics: Web Development

Browse Happy logo