There are a lot of websites using a extra <span>-tag for the drop cap. But using the :first-letter pseudo-element, you can easily create nice drop caps with CSS. :first-letter will – how surprising – target the first letter of an element. This pseudo element is included in CSS 1, so the browser support is very good. It’s supported by IE5+, Let’s design some nice drop caps with CSS.
Designing
Unfortunately you can only apply a limited amount of properties to a first letter. According to w3schools only font, color, background, margin, padding, border, float and some other properties can be applied. Still you can make a nice drop cap with CSS.
I used this CSS code:
p:first-letter {
display:block;
float:left;
border:1px solid black;
padding:5px;
margin:4px 5px;
background:url(firstletter1.png);
font-size:73px;
}
This image of Wikipedia Commons was used for the background image. Click here to view the example page.
I have some issues with this in Opera: the background doesn’t have the same height as the text. I don’t really know how to fix this, because there is no way to specify the height of the first letter in CSS. It works good in all other major browsers.
- BROWSE / IN TIMELINE
- « How to make RSS icons in every colour with just one image
- » 12 Articles and Tools for CSS structuring and optimising
- BROWSE / IN CSS Featured
- « How to make RSS icons in every colour with just one image
- » 12 Articles and Tools for CSS structuring and optimising