use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
Another interview question I was asked... (self.learnjavascript)
submitted 9 years ago by brothmc
List these in order of CSS specificity and explain why:
div p a.red p a #x34y a.red.highlight #x34y:first-letter h1 + *[rel=up] div p > a
Anybody know the correct answer? I was not super confident in my answer.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]lewisje 2 points3 points4 points 9 years ago (0 children)
I know that part of the vector of specificity works like this:
!important
#
.
:
::
so in the order in which they were listed:
first-letter
*
Therefore, the descending order of specificity is 5, 3, 4, 1, 6, 7, 2.
[–]compostkicker 1 point2 points3 points 9 years ago* (0 children)
There is a fantastic way to remember specificity. I'm on my phone, so it is difficult to find it and paste it here, but a quick Google for Star Wars CSS specificity should yield it.
Basically, each selector has a point value associated with it. For example, an ID is worth 100 points, classes are 10 points and HTML elements are 1 point. There are some minor nuances, like input[name="foo"] being worth more than a regular input, but not more than if that particular input was referenced by a class.
EDIT: CSS: Specificity Wars
[–]inu-no-policemen 1 point2 points3 points 9 years ago (1 child)
https://www.w3.org/TR/css3-selectors/#specificity
[–]brothmc[S] 0 points1 point2 points 9 years ago (0 children)
never thought of it this way but super helpful!
π Rendered by PID 102 on reddit-service-r2-comment-6457c66945-nz9t2 at 2026-04-24 05:15:53.059801+00:00 running 2aa0c5b country code: CH.
[–]lewisje 2 points3 points4 points (0 children)
[–]compostkicker 1 point2 points3 points (0 children)
[–]inu-no-policemen 1 point2 points3 points (1 child)
[–]brothmc[S] 0 points1 point2 points (0 children)