CSS Selectors Flashcards
What does ul + p selector do?
Select only the first p that comes immediately after a ul.
What does ul ~ p selector do?
Select any p elements that are siblings to ul even if they don’t follow immediately. Doesn’t cover p elements that come before, however.
Find all images that end in .jpg
img [ src$=”jpg” ] (note: can’t have space between words)
Find all tags with a link that begins with “http”;
a[href^=”http”]
What is the pattern for finding elements based on attributes (not class or ID)? What if a word is first, last, or appears anywhere?
elementName[attr=value];
elName[attr^=value], *[attr$=value], etc.
Find all elements that have a style set on them by javascript no matter what type of element.
*[style]
Find all radio buttons that are checked
input[type=”radio”]:checked
Select every second item in a list
li:nth-child(2n);
Select just the second to last item in a list
li:nth-last-child(2);
Select every other child paragraph of a div
div > p:nth-of-type(2n)
Select the first, last, or only element in a collection.
:first-child | :first-of-type | :last-child | only-child
Select first letter or first line of a paragraph
::first-letter or ::first-line (note double color for pseudo elements)
Select all classes ending in “-area” (e.g. class=”title-area” or “content-area”)
[class$=”-area”] { …