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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:30:23+00:00 2026-05-29T05:30:23+00:00

How does CSS determine when to apply one style over another? I have been

  • 0

How does CSS determine when to apply one style over another?

I have been through the W3 CSS3 selectors document a few times, and that has helped me understand how to better use CSS selectors in jQuery, but it has not really helped me understand when one CSS rule will be applied over another.

I have the following the HTML:

<div class='item'>
    <a>Link 1</a>
    <a class='special'>Link 2</a>
</div>

I have the following CSS:

.item a {
    text-decoration: none;
    color: black;
    font-weight: bold;
    font-size: 1em;
}

.special {
    text-decoration: underline;
    color: red;
    font-weight: normal;
    font-size: 2em;
}

Given the above, both Link 1 and Link 2 will be styled the same, as determined by the .item a CSS. Why does the style associated with .special not take precedence for Link 2?

Obviously, I can get around it like this:

.special {
    text-decoration: underline !important;
    color: red !important;
    font-weight: normal !important;
    font-size: 1em !important;
}

But, I feel like that is a hack that I have to sprinkle in due to my lack of understanding.

  • 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-05-29T05:30:24+00:00Added an answer on May 29, 2026 at 5:30 am

    It’s based on IDs, classes and tags. IDs have the highest specificity, then classes then tags, so:

    .item a     == 0 1 1      0 (id) 1 (class=item) 1 (tag=a)
    .special    == 0 1 0
    #foo        == 1 0 0
    #foo .bar a == 1 1 1
    #foo #bar   == 2 0 0
    

    whichever has the most wins 🙂 If it’s a tie, whichever one comes last in the document wins. Note that 1 0 0 beats 0 1000 1000

    If you want .special to apply, make it more specific: .item a.special

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

Sidebar

Related Questions

I have this CSS style that does a rounded corners for div border, but
Does css hover work on mobile devices? I have a css hover class which
How does one create Dynamic CSS and JavaScript On-The-Fly (using PHP). This needs to
How does one go about establishing a CSS 'schema', or hierarchy, of general element
Supposing no CSS, javascript or other HTML trickery, how does the browser determine the
Better add images through HTML and determine alt tags, or add through CSS with
I have following HTML+CSS markup: <div id=protofade style=position: relative;> <div style=position: absolute;><img src=slide-01.jpg></div> <div
Does the css visibility style collapse work in IE8? The reason I ask this
Possible Duplicate: Inherit CSS class Does CSS support inheritance ? Assuming we have: .base
Does the css content property break the rule of content and separation because css

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.