Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9302733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:19:21+00:00 2026-06-18T23:19:21+00:00

I was playing around with CSS selectors, when I ran into a weird situation.

  • 0

I was playing around with CSS selectors, when I ran into a weird situation.

If I use :first-child pseudo-element I need to prepend it with a space for it to work, If I don’t it will not work. However with :first-letter pseudo-element situation is reverse, it will work only if it is not prepended by space.

I find it quite inconsistent as those are both pseudo elements. Initially I thought it may be just IE10 issue, but I checked with Chrome and Firefox with the same results. Is there something I am missing? Is there a reason for this behavior?

Here, is the compact sample reproducing the issue:

<!DOCTYPE html>
<html>
<head>
<style>
    * { color: red; }
    #article1 :first-child { color: deepskyblue; }
    article :last-child { color: darkmagenta; }
    #firstLetter:first-letter { color: darkslateblue; }
    #firstLine:first-line { color: darkslateblue; }
</style>
</head>
<body>
    <article id="article1">
        <div>E :first-child </div>
        <div>E :last-child </div>
    </article>                        
    <div id="firstLetter">:first-letter</div>
    <div id="firstLine">:first-line</div>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T23:19:22+00:00Added an answer on June 18, 2026 at 11:19 pm

    Your confusion comes from the fact that :first-child and :last-child are pseudo-classes, not pseudo-elements. Each of them mean the first and last child of its parent respectively, but the element you attach them to represents the child, not the parent. A pseudo-class is a description of a certain element, if you will, just like an ID selector describes an element with that ID or an attribute selector describes an element with that attribute. So, the selector E:first-child means E that is the first child of its parent — whatever that parent may be — but not the first child of E.

    The selector #article1:first-child should match #article1 since it’s the first child of body, but it will not match the div that is the first child of #article1. #article1 :first-child matches the div because, well, it’s the first child whose parent happens to be #article1.

    On the other hand, :first-letter and :first-line work because they match the first letter and first line of each element respectively. This is what is meant by a pseudo-element; a virtual element (not represented in the DOM) that’s generated as a member of some other element.

    Note that this doesn’t mean you can or cannot use the space with one or the other. You can use any combinator with any pseudo-class or pseudo-element selector, or attach it to another chain of simple selectors. They just mean different things when used with or without a combinator, which is why you’re seeing different results.

    Another explanation of pseudo-classes versus pseudo-elements can be found here.

    If you don’t need to support IE8 and older, you should represent pseudo-elements using double colons to help you distinguish them from pseudo-classes, so ::first-letter and ::first-line instead of :first-letter and :first-line. This notation is introduced in the new Selectors module.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm playing around with css transforms and the equivalent filters in IE, and want
I just started playing around with the 960 CSS framework and found that it
Playing around with Python - tkInter - Entry widget - when I use validatecommand
I am playing around with CSS Sticky Footer and I have an issue where...
I'm playing around with Google maps for the first time, so I looked at
Hey guys playing around with CSS. I made a box. Basically what iam trying
We have been playing around with the canvas element, but are encountering sluggishness on
Why on earth does the IMG element have the CSS color property? After playing
I am playing around with jQuery and thought I would build a little css
I'm playing around with Symfony2 , and I have problems including CSS and JS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.