| Start | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Attribute Selectors OverviewAttribute selectors can be used with various types of operators that change the selection criteria accordingly. They select an element using the presence of a given attribute or attribute value.
Notes: Details |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Basic selectors
Note: The value of an ID must be unique in a web page. It is a violation of the HTML standard (opens new window) to use the value of an ID more than once in the same document tree. A complete list of selectors can be found in the CSS Selectors Level 3 specification (opens new window). |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Combinators Overview
Note: Sibling selectors target elements that come after them in the source document. CSS, by its nature (it cascades), cannot target previous or parent elements. However, using the flex Descendant Combinator: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pseudo-classes Pseudo-classes (opens new window) are keywords which allow selection based on information that lies outside of the document tree or that cannot be expressed by other selectors or combinators. This information can be associated to a certain state (state (opens new window) and dynamic (opens new window) pseudo-classes), to locations (structural (opens new window) and target (opens new window) pseudo-classes), to negations of the former (negation (opens new window) pseudo-class) or to languages (lang (opens new window) pseudo-class). Examples include whether or not a link has been followed ( SyntaxList of pseudo-classes:
The |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Child Pseudo Class "The :nth-child(an+b) CSS pseudo-class matches an element that has an+b-1 siblings before it in the document tree, for a given positive **or zero value** for n" - [MDN :nth-child](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Class Name Selectors The class name selector select all elements with the targeted class name. For example, the class name You can also combine class names to target elements more specifically. Let's build on the example above to showcase a more complicated class selection. CSS HTML In this example, all elements with the Notice that within the CSS, the If a space was included between the two classes in the CSS declaration, it would only select elements that have parent elements with a |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Select element using its ID without the high specificity of the ID selector This trick helps you select an element using the ID as a value for an attribute selector to avoid the high specificity of the ID selector. HTML: CSS |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Global boolean with checkbox:checked and ~ (general sibling combinator) With the ~ selector, you can easily implement a global accessible boolean without using JavaScript. Add boolean as a checkboxTo the very beginning of your document, add as much booleans as you want with a unique Change the boolean's valueYou can toggle the boolean by adding a Accessing boolean value with CSSThe normal selector (like Note that Examples for the above HTML structure would be: In actionSee this fiddle (opens new window) for a implementation of these global booleans. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CSS3 :in-range selector example The |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| A. The :not pseudo-class example & B. :focus-within CSS pseudo-class A. The syntax is presented above. The following selector matches all HTML: CSS: The CSS: Live Demo on JSBin (opens new window) See background syntax here (opens new window). B. The :focus-within CSS pseudo-class HTML: CSS: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| The :last-of-type selector The |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ID selectors ID selectors select DOM elements with the targeted ID. To select an element by a specific ID in CSS, the For example, the following HTML …can be selected by Note: The HTML specs do not allow multiple elements with the same ID |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| How to style a Range input HTML CSS
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| The :only-child pseudo-class selector example The HTML: CSS: The above example selects the Live Demo on JSBin (opens new window) Syntax
Remarks
|
Read Article
https://develop.horje.com/learn/1434/reference