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 8926491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:59:02+00:00 2026-06-15T07:59:02+00:00

I am confused about a simple behaviour of CSS. I have some <a class=cool-element></a>

  • 0

I am confused about a simple behaviour of CSS.

I have some <a class="cool-element"></a> elements in the DOM, and no other types of elements in the dom have the `”cool-element” class, not even the divs. So I did this to try to select them:

.cool-element {
  background-color: red;
}

that to my surprise did not work. But if I do

a.cool-element {
  background-color: red;
}

I get the expected result. I test this in Firefox and in an app that has a lot of other CSS rules loaded. I haven’t tested this in isolation, but I am pretty sure in some other places I am using the first selector with success. Isn’t the first selector here supposed to work perfectly fine all the times, or am I missing something?

  • 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-15T07:59:03+00:00Added an answer on June 15, 2026 at 7:59 am

    CSS specificity

    In CSS more specific rules take precedence over less specific rules. You can calculate the specificity of a given selector using the following

    1. +1000 for inline styles – Inline styles always take precedence
    2. +100 for an id – the id attribute of an element
    3. +10 for class or pseudo-class – the class attribute or :hover
    4. +1 for an element or pseudo element – html, body, div, p… or :first, :last

    A selector overrides all selectors with less point than it. If they have the same number of points then order matters.

    Examples

    a.class-name = 1 + 10 = 11
    a#id.class-name = 1 + 100 + 10 = 111
    a.class-name.class2-name = 1 + 10 + 10 = 21
    

    Until I learned how the points are calculated CSS was a dark art in my mind. There is a good article on css-tricks which might do a better job of explaining it – jump to the Calculating CSS Specificity Value section

    Order matters

    As Jorge Alvarado mentioned order matters, so if you have two rules that apply to the same elements, the second style will override the first one.

    a.class-name { background: red } #this rule will be overridden
    a.class-name { background: green } #this rule will be applied
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am confused about something really simple in ASP.NET. I have seen many times
Should be a simple question for SDL experts. I am confused about the following
I'm a newbie to Java and I'm confused about something: In the simple hello
I am a little confused about Accept-Encoding . I have Web Service which would
I am a bit confused about the 'rules' of when a TextView element displays
I'm a little bit confused about simple program which I wrote, can You please
In a simple example, I'm confused about how to turn this grammar into a
I am confused about how to use destructors when I have a std::vector of
I'm a little confused about the default behaviour of Equals and GetHashCode in C#.
I'm confused about simple problem: What is the difference between the active record and

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.