CSS - Selectors Flashcards

1
Q

:link

A

The:linkselector is used to select unvisited links.

Note:The :link selector does not style links you have already visited.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

:visited

A

The:visitedselector is used to select visited links.

a:visited{
color:pink;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

:hover

A

Select and style a link when you mouse over it:

a:hover{
background-color:yellow;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

:active

A

Select and style the active link:

a:active{
background-color:yellow;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

element>element

A

Select and style every <p> element where the parent is a </p><div> element:

div > p{
background-color:yellow;
}

</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

element+element

A

Select and style the first <p> element that are placed immediately after </p><div> elements:

div + p{
background-color:yellow;
}

</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

element1~element2

A

Set a background color for all <ul> elements that are preceded by a <p> element with the same parent:

p ~ ul{
background:#ff0000;
}

</p></ul>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

[attribute]

A

Style all <a> elements with a target attribute:</a>

a[target]{
background-color:yellow;
}

</a>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

[attribute=value]

A

Style <a> elements with a target=”_blank”:</a>

a[target=_blank]{
background-color:yellow;
}

</a>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

[attribute~=value]

A

Select and style elements with a title attribute containing the word “flower”:

[title~=flower]{
background-color:yellow;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

[attribute|=value]

A

Select and style elements, where the lang attribute’s value starts with “en”:

[lang|=en]{
background-color:yellow;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

[attribute^=value]

A

Set a background color on all <div> elements that have a class attribute value that begins with “test”:

div[class^=”test”]{
background:#ffff00;
}

</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

[attribute$=value]

A

Set a background color on all <div> elements that have a class attribute value that ends with “test”:

div[class$=”test”]{
background:#ffff00;
}

</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

[attribute*=value]

A

Set a background color on all <div> elements that have a class attribute value containing “test”:

div[class*=”test”]{
background:#ffff00;
}

</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

::after

A

Insert some text after the content of each <p> element:

p::after{
content:” - Remember this”;
}

</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

::before

A

Insert some text before the content of each <p> element:

p::before{
content:”Read this: “;
}

</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

:checked

A

Set the height and width for all checked elements:

input:checked{
height:50px;
width:50px;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

:default

A

Add a red shadow color to the default input element:

input:default{
box-shadow:0 0 1px 1px red;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

:disabled

A

Set a background color for all disabled input elements of type=”text”:

input[type=”text”]:disabled{
background:#dddddd;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

:empty

A

Specify a background color for empty <p> elements:

p:empty{
background:#ff0000;
}

</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

:enabled

A

Set a background color for all enabled elements of type=”text”:

input[type=”text”]:enabled{
background:#ffff00;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

:first-child

A

Select and style every <p> element that is the first child of its parent:

p:first-child{
background-color:yellow;
}

</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

::first-letter

A

Select and style the first letter of every <p> element:

p::first-letter{
font-size:200%;
color:#8A2BE2;
}

</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

::first-line

A

Select and style the first line of every <p> element:

p::first-line{
background-color:yellow;
}

</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
:first-of-type
Specify a background color for the first

element of its parent: p:first-of-type {   background: red; }

26
:focus
Select and style an input field when it gets focus: input:focus {   background-color: yellow; }
27
:fullscreen
Set the background color to yellow when the page is in full-screen mode: :fullscreen {   background-color: yellow; }
28
:hover
Select and style a link when you mouse over it: a:hover {   background-color: yellow; }
29
:in-range
Select and style only if the value of the element is "in range": input:in-range {   border: 2px solid yellow; }
30
:indeterminate
Add a red shadow color to indeterminate inputs: input:indeterminate {   box-shadow: 0 0 1px 1px red; }
31
:invalid
Select and style only if the value of the element is invalid: input:invalid {   border: 2px solid red; }
32
:lang
Select and style every

element with a lang attribute value equal to "it" (Italian): p:lang(it) {   background: yellow; }

33
:last-child
Specify a background color for the

element that is the last child of its parent: p:last-child {   background: #ff0000; }

34
:last-of-type
Specify a background color for the last

element of its parent: p:last-of-type {   background: #ff0000; }

35
:link
Select and style unvisited links: a:link {   background-color: yellow; }
36
::marker
Style the markers of list items: ::marker {   color: red; }
37
:not
Set a background color for all elements that are not a

element: :not(p) {   background: #ff0000; }

38
:nth-child()
How to use the :nth-child() selector: ``` /* Selects the second element of div siblings */ div:nth-child(2) {   background: red; } ``` ``` /* Selects the second li element in a list */ li:nth-child(2) {   background: lightgreen; } ``` ``` /* Selects every third element among any group of siblings */ :nth-child(3) {   background: yellow; } ```
39
:nth-last-child()
Specify a background color for every

element that is the second child of its parent, counting from the last child: p:nth-last-child(2) {   background: red; }

40
:nth-last-of-type()
Specify a background color for every

element that is the second p element of its parent, counting from the last child: p:nth-last-of-type(2) {   background: red; }

41
:nth-of-type()
How to use the :nth-of-type() selector: ``` /* Selects the second element of div siblings */ div:nth-of-type(2) {   background: red; } ``` ``` /* Selects the second li element in a list */ li:nth-of-type(2) {   background: lightgreen; } ``` ``` /* Selects every third element among any group of siblings */ :nth-of-type(3) {   background: yellow; } ```
42
:only-of-type
Specify a background color for every

element that is the only child of its type, of its parent: p:only-of-type {   background: #ff0000; }

43
:only-child
Specify a background color for every

element that is the only child of its parent: p:only-child {   background: #ff0000; }

44
:optional
Select and style only if the element does not have a "required" attribute: input:optional {   background-color: yellow; }
45
:out-of-range
Select and style only if the value of the element is "out of range": input:out-of-range {   border: 2px solid red; }
46
::placeholder
Change the color of the placeholder text of an input field: ::-webkit-input-placeholder { /* Edge */   color: red; } :-ms-input-placeholder { /* Internet Explorer 10-11 */   color: red; } ::placeholder {   color: red; }
47
:read-only
Select and style only if the input element is "readonly": input:read-only {   background-color: yellow; }
48
:read-write
Select and style only if the input element is not "readonly": input:read-write {   background-color: yellow; }
49
:required
Select and style only if the element has a "required" attribute: input:required {   background-color: yellow; }
50
:root
Set the background color for the HTML document: :root {   background: #ff0000; }
51
::selection
Make the selected text red on a yellow background: ::selection {   color: red;   background: yellow; }
52
:target
Highlight active HTML anchor: :target {   border: 2px solid #D4D4D4;   background-color: #e5eecc; }
53
:valid
Select and style only if the value of the element is valid: input:valid {   background-color: yellow; }
54
:visited
Select and style visited links: a:visited {   color: pink; }
55
element element
Select and style every

element that is inside

elements: div p {   background-color: yellow; }
56
element,element
Select and style all

elements AND all

elements: h2, p {   background-color: yellow; }

57
element.class
Select and style every

element with the class "intro": p.intro {   background-color: yellow; }

58
element
Select and style all

elements: p {   background-color: yellow; }

59
*
Select all elements, and set their background color to yellow: * {     background-color: yellow; }
60
#id
Style the element with id="firstname": ``` #firstname {   background-color: yellow; } ```
61
.class
Select and style all elements with class="intro": .intro {   background-color: yellow; }