- September 21, 2016
- Posted by: Renee Rodriguez
- Category: Web Development
As a front end developer, there can be a lot that is needed to be remembered. With all the different computer languages out and coming out, we always need to stay on top of the game. All developers should consider updating themselves and making their work better. Here are some CSS Selectors that you may not be aware of.
1. A + B
This is a simple selector that helps you select only the elements placed immediately after (not inside) the first element.
2. A > B
This is the child selector. It selects all elements that are direct children of a specified element.
This is an attribute selector, this selects elements with a specific attribute.
A CSS3 pseudo class that only targets elements that are checked. Keep in mind, it only works with radio buttons and checkboxes.
Another CSS3 pseudo class, this selector only targets every disabled element. This too affects only radio buttons and checkboxes, ultimately, this would only affect the default state of those selectors.
This selector only affects elements which are marked as required in forms.
This selector selects elements with validated value as per its element settings. This works mainly with email fields, input with max and min attributes or number fields.
This selector is the exact opposite of :valid. It selects elements those doesn’t validated valid as per its element settings.
the :after and :before pseudo classes are very useful when you want to add some content after or before an element. Some of the most common uses for these selectors are clearfixs and using quotes in blockquotes.
This pseudo class is used with IDs and it only works when # tag in the URL matches with the ID of an element.
:not(selector) targets every element which doesn’t match the specified element/selector. It is useful when you want to target all element except one particular element.
12. A::text related pseudo elements
This is for ::first-line and ::first-letter pseudo elements. ::first-line selects the first line of a specified element, whereas ::first-letter selects the first letter in the text of the element. These selectors can only be used with block-level elements.
This selector allows you to select the first element of its parents. This is very useful when you want to style the first item in a list.
Similar to :first-child selector, :last-child allows you to select the last element of its parent.
:Nth-child selector allows you to select one or multiple elements of any type of its parent.
This selector works like :nth-child but it selects elements of a particular type of its parent.
The :first-of-type selector selects the first element of a particular type of its parent.
Similar to :first-of-type, :last-of-type selects the last elements of a particular type of its parents.
This works similarly as :nth-of-type. The only difference is that it starts counting from the last child.
This is similar to :nth-child but it starts counting from the last child.
For demos and examples of all these selectors, be sure to take a look at this article.