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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:33:59+00:00 2026-06-18T17:33:59+00:00

I learned about selector precedence from this tutorial . I have trouble understanding the

  • 0

I learned about selector precedence from this tutorial. I have trouble understanding the behavior of this in one case. I have an element in HTML:

<input class="top_bar_login_form_input" type="text"  name="email" placeholder="Prijavno ime">

The problem is that properties from another selector override the properties from the class.

Picture

As shown in the picture above the class gets overridden by a less specific selector. The element gets selected by input[type="text"], which is less specific than a class. The only reasoning behind these behavior that I see is that the .inputbox class is also calculated in determining the precedence, even though it doesn’t match the element.

Why does the type selector override the class selector?

  • 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-18T17:34:00+00:00Added an answer on June 18, 2026 at 5:34 pm

    TL;DR Answer

    The first rule is more specific than the second one because it has both a type and attribute part for the selector, and thus has precedence:

    input[type="text"] { }         /* type + attribute for specificity */
    .top_bar_login_form_input { }  /* only class for specificity, so *less* specificity */
    

    Longer answer

    You’d think that the type="text" bit, which is an attribute selector, is more specific than a class selector, in accordance with the MDN page on specificity:

    The following list of selectors is by increasing specificity:

    • Universal selectors
    • Type selectors
    • Class selectors
    • Attributes selectors
    • Pseudo-classes
    • ID selectors
    • Inline style

    The above quote was in the MDN article at the time this answer was written.

    Why that is misleading:

    (Tanks to @BoltClock’s insights.)

    The above only seems correct, but that’s because you typically include the element in the selector (e.g. input[type="text"]) when doing an attribute selector. However, what’s sneaky: the input bit matters.

    Suppose we have the following markup:

    <input class="my-class" type="text" value="some value" />
    

    In the following scenario the input renders red:

    [type="text"] { color: green; }
    .my-class { color: red; }             /* last rule matched */
    

    If we reverse the rules in a scenario, the input will render green:

    .my-class { color: red; }
    [type="text"] { color: green; }       /* last rule matched */
    

    This is because both selectors have equal specificity. Now introducing the input selector to the attribute rule will make one of them more specific, which can be seen in this scenario:

    input[type="text"] { color: green; }  /* most _specific_ rule matched */
    .my-class { color: red; }
    

    The W3 spec makes my head hurt, but it does have the details on why the above works. See also the answer by @BoltClock and comments in those code examples for info on how the specificity is calculated.

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

Sidebar

Related Questions

From this tutorial I learned about Regular Expressions - Quantifiers, and based on this
I learned about multiprocessing from Python and I'm having a bit of trouble understanding
I have recently learned about continuous integration. From my understanding, its a way to
I learned about how to browse my local App Engine Datastore from this handy
I have just learned about recursion in Python and have completed assignments, one of
I have just learned about XPath and I am wanting to read data from
From what I have learned about Mutexes - they generally provide a locking capability
I just learned about ThreadLocal this morning. I read that it should always be
So far I have learned about generating thread dump and heap dump using jstack
I just posted this question and learned about <see cref=> , however when i

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.