Add to Favorites

CSS Tips | :first-child

Using the CSS pseudo-class :first-child allows you to style any thing that is the "first child" of another element. One case that this may be helpful is when you want a different style for the first li element in your list. i.e. additional margin, color, etc. This would be done like this.

ul li:first-child {
margin-top: 20px;
color: #000000;
}

Support for this pseudo-class is limited to Firefox, Safari and versions of Internet Explored later than IE6.

Comments

Be the first to leave a comment on this post.

Leave a comment

To leave a comment, please log in / sign up