Selectors are patterns that match against elements in a document tree. In a CSS rule, they are used to define styles for elements that match the pattern.
397
votes
15answers
262k views
Is there a CSS parent selector?
I would like to select the <li> element that is a parent (which immediately precedes the anchor tag, if that helps...) according to some attribute of the anchor tag.
i.e. my CSS would be ...
303
votes
7answers
98k views
What characters are valid in CSS class selectors?
What characters/symbols are allowed within CSS class selectors? Characters such as:
~ ! @ $ % ^ & * ( ) _ + - = , . / ' ; : " ? > < [ ] \ { } | ` #
I know a lot of these are invalid, but ...
218
votes
2answers
26k views
Why do browsers match CSS selectors from right to left?
CSS Selectors are matched by browser engines from right to left. So they first find the children and then check their parents to see if they match the rest of the parts of the rule.
Why is this?
Is ...
140
votes
3answers
51k views
CSS previous sibling selector
+ is for the next sibling. Is there an equivalent for the previous sibling?
132
votes
11answers
91k views
Complex CSS selector for parent of active child [duplicate]
Is there a way to select a parent element based on the class of a child element in the class? The example that is relevant to me relating to HTML output by a nice menu plugin for http://drupal.org. ...
93
votes
4answers
24k views
CSS Child vs Descendant selectors
I am a bit confused between these 2 selectors. Does the descendent selector:
div p
select all p within a div whether or not it's an immmediate descedent? So if the p is inside another div it will ...
89
votes
5answers
2k views
What does the * * CSS selector do?
Recently I came across * * in CSS.
Site reference - Site Link.
For a single * usage in CSS style sheet, Internet and Stack Overflow is flooded with examples, but I am not sure about using two * * ...
85
votes
2answers
66k views
How can I get the second child using CSS?
I have a table whose tds are created dynamically. I know how to get the first and last child but my question is:
Is there a way of getting the second or third child using CSS?
79
votes
11answers
129k views
using last-child in css
the below css doesnt works on below given html.
The purpose is to apply the css on the last 'li', but it doesnt.
#refundReasonMenu #nav li:last-child
{
border-bottom: 1px solid #b5b5b5;
}
and ...
76
votes
4answers
91k views
CSS Selector for <input type=“?”
Is there any way with CSS to target all inputs based on their type? I have a disabled class I use on various disabled form elements, and I'm setting the background color for text boxes, but I don't ...
69
votes
6answers
46k views
wildcard * in CSS for classes
I have these divs that I'm styling with .tocolor, but I also need the unique identifier 1,2,3,4 etc. so I'm adding that it as another class tocolor-1.
<div class="tocolor tocolor-1"> tocolor ...
69
votes
5answers
7k views
Points in CSS specificity
Researching specificity I stumbled upon this blog - http://www.htmldog.com/guides/cssadvanced/specificity/
It states that specificity is a point-scoring system for CSS. It tells us that elements are ...
67
votes
6answers
85k views
CSS selector for first element with class
I have a bunch of elements with a class name red:
<p class="red"></p>
<div class="red"></div>
I can't seem to select the first element with the class="red" using the ...
62
votes
1answer
24k views
Select elements by data attribute in CSS
Is it possible to select elements in CSS by their HTML5 data attributes (for example, data-role)?
60
votes
2answers
3k views
Are class names in CSS selectors case sensitive?
I keep reading everywhere that CSS is not case sensitive, but I have this selector
.holiday-type.Selfcatering
which when I use in my HTML, like this, gets picked up
<div class="holiday-type ...