Why does bootstrap accept form styling for only one highly specific css classes?

user1876508

I have a jsbin with a table of inputs, using bootstrap. What confuses me is that the style with

input.someClass {
    background-color: blue;
}

is applied, as expected, but

.anotherClass {
    background-color: green;
}

is not applied to my input elements. What is the reason for this? For reference, check out http://jsbin.com/enaris/3/edit

Jason Yaraghi

What is the reason for this?

It's simply a matter of specificity - the first selector has a type selector attached to the class name whereas the second selector only has a single class. The second selector is therefore more specific and takes precedence.

This is migrated from another answer of mine, it may help:

You can think of specificity as four numbers, starting with (0,0,0,0):

  • !important rules always take precedence, only another !important rule can override a previous one (its an accessibility feature of CSS, designed to override the UA stylesheet)
  • The universal selector (*) has a specificity of 0
  • Combinators like + and ~ also have no specificity
  • Inline styles have the highest specificity (other than !important) and count as the first number (1,0,0,0)
  • ID's (#test) count as the second number in the above set (0,1,0,0)
  • Classes, pseudo-classes and attribute selectors are the third number (0,0,1,0)
  • Type selectors and psuedo-elements (e.g. - <p> & ::after) take place of the fourth number, and are the least specific
  • Remember that if two rules have the same specificity and specify the same property the latter in the stylesheet will win

Based on the above, the first selector has a specifictiy of (0,0,1,1) while the second only has (0,0,1,0)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why is CSS not styling this Bootstrap webpage?

From Dev

Why does Clojure's for macro only accept one body expression?

From Dev

Why does my file input only accept one file?

From Dev

bootstrap form input accept text only

From Dev

Accept only one or more files in html form

From Dev

Correct naming convention for styling only classes in Bootstrap 3?

From Dev

Why does the controller in spring boot only accept data of json type and doesn't accept data submitted from thymeleaf form?

From Dev

Styling form in bootstrap 3

From Dev

Why does forEach method accept lambda that invokes method with multiple arguments when Consumer only takes one argument?

From Dev

Why form lost bootstrap css?

From Dev

Bootstrap CSS Styling troubles

From Dev

Search Form Styling CSS

From Dev

Styling a checkbox with css only

From Dev

Checkbox styling only css

From Dev

CSS select an element that contains specific classes only

From Dev

Why does radiobutton CSS-styling behave opposite to checkbox?

From Dev

Styling CSS of Programmatically created classes

From Dev

CSS Checkbox styling unique classes

From Dev

Styling CSS of Programmatically created classes

From Dev

Why does bootstrap use '!important' for responsive classes?

From Dev

Why does Matlab only accept a small set of characters in script filenames?

From Dev

Why does Elm.embed only accept divs?

From Dev

Why does find -exec only accept {} in some positions?

From Dev

Bootstrap DatePicker CSS Styling not Working

From Dev

why bootstrap modal works only for one item

From Dev

Styling a disabled input with css only

From Dev

Why is razor not adding the proper bootstrap classes to form controls?

From Dev

Why is razor not adding the proper bootstrap classes to form controls?

From Dev

Why does operator[] only take one argument?

Related Related

  1. 1

    Why is CSS not styling this Bootstrap webpage?

  2. 2

    Why does Clojure's for macro only accept one body expression?

  3. 3

    Why does my file input only accept one file?

  4. 4

    bootstrap form input accept text only

  5. 5

    Accept only one or more files in html form

  6. 6

    Correct naming convention for styling only classes in Bootstrap 3?

  7. 7

    Why does the controller in spring boot only accept data of json type and doesn't accept data submitted from thymeleaf form?

  8. 8

    Styling form in bootstrap 3

  9. 9

    Why does forEach method accept lambda that invokes method with multiple arguments when Consumer only takes one argument?

  10. 10

    Why form lost bootstrap css?

  11. 11

    Bootstrap CSS Styling troubles

  12. 12

    Search Form Styling CSS

  13. 13

    Styling a checkbox with css only

  14. 14

    Checkbox styling only css

  15. 15

    CSS select an element that contains specific classes only

  16. 16

    Why does radiobutton CSS-styling behave opposite to checkbox?

  17. 17

    Styling CSS of Programmatically created classes

  18. 18

    CSS Checkbox styling unique classes

  19. 19

    Styling CSS of Programmatically created classes

  20. 20

    Why does bootstrap use '!important' for responsive classes?

  21. 21

    Why does Matlab only accept a small set of characters in script filenames?

  22. 22

    Why does Elm.embed only accept divs?

  23. 23

    Why does find -exec only accept {} in some positions?

  24. 24

    Bootstrap DatePicker CSS Styling not Working

  25. 25

    why bootstrap modal works only for one item

  26. 26

    Styling a disabled input with css only

  27. 27

    Why is razor not adding the proper bootstrap classes to form controls?

  28. 28

    Why is razor not adding the proper bootstrap classes to form controls?

  29. 29

    Why does operator[] only take one argument?

HotTag

Archive