*** From the Archives ***

This article is from August 17, 2009, and is no longer current.

CSS Fundamentals

Styles for Parts of a Paragraph
To draw attention to an introduction or opening statement, one common practice is to make the first letter or first line of text in a paragraph stand out from the rest of the text on the page. A paragraph is a block of text, so it has a first letter and a first line of characters, but they do not have specific HTML tags around them. To style these you can use pseudo-elements for the first-letter and first line:
The first letter of each paragraph is red.
p:first-letter { color: red; }
The first line of each paragraph is blue
p:first-line { color: blue }
Keep in mind, though, that this applies the style indiscriminately to all paragraph tags on the page. If we want to style only the first letter or line of the first paragraph in our content, we would need to style it based on its context as the first child of a particular element (let’s ID it as content).
The first letter in a paragraph within any tag with the content ID has a color of red.
#content+p:first-letter { color: red; }
<div id=“content”><p>One thing was certain</p></div>
The only drawback to this method is that it will not work in IE6, which does not recognize the child context.


Excerpted from Speaking in Styles: Fundamentals of CSS for Web Designers, and used with the permission of New Riders and Peachpit Press.
 


Previous 1 2

  • Anonymous says:

    Truly, very well written and your use of graphics is superb! I am just more than a newby to all this stuff – a very frustrated web developer – love the challenge but have difficulty remembering all the fine details. This article covers key steps in a very understandable way and builds slowly to more complex levels. It show the author’s and editors’ expertise and right-on capabilities as being superior!

    Thanks and I look forward to others.
    Steve King

  • Anonymous says:

    Very informative article, even for one like me who doesn’t speak CSS

  • Anonymous says:

    great article that really helped me out in understanding some css!

  • Anonymous says:

    And as a previous commenter said the author demonstrates a very astute use of graphics.

  • Anonymous says:

    This is one of the best css books I have ever purchased. I highly recommend it to everyone

  • Anonymous says:

    Very Lucid and apt enabling novice to catch up the principle and usage.
    -Shankar

  • >