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
Q

:first-of-type

A

Specify a background color for the first <p> element of its parent:

p:first-of-type{
background:red;
}

</p>

26
Q

:focus

A

Select and style an input field when it gets focus:

input:focus{
background-color:yellow;
}

27
Q

:fullscreen

A

Set the background color to yellow when the page is in full-screen mode:

:fullscreen{
background-color:yellow;
}

28
Q

:hover

A

Select and style a link when you mouse over it:

a:hover{
background-color:yellow;
}

29
Q

:in-range

A

Select and style only if the value of the element is “in range”:

input:in-range{
border:2px solid yellow;
}

30
Q

:indeterminate

A

Add a red shadow color to indeterminate inputs:

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

31
Q

:invalid

A

Select and style only if the value of the element is invalid:

input:invalid{
border:2px solid red;
}

32
Q

:lang

A

Select and style every <p> element with a lang attribute value equal to “it” (Italian):

p:lang(it){
background:yellow;
}

</p>

33
Q

:last-child

A

Specify a background color for the <p> element that is the last child of its parent:

p:last-child{
background:#ff0000;
}

</p>

34
Q

:last-of-type

A

Specify a background color for the last <p> element of its parent:

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

</p>

35
Q

:link

A

Select and style unvisited links:

a:link{
background-color:yellow;
}

36
Q

::marker

A

Style the markers of list items:

::marker{
color:red;
}

37
Q

:not

A

Set a background color for all elements that are not a <p> element:

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

</p>

38
Q

:nth-child()

A

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
Q

:nth-last-child()

A

Specify a background color for every <p> element that is the second child of its parent, counting from the last child:

p:nth-last-child(2){
background:red;
}

</p>

40
Q

:nth-last-of-type()

A

Specify a background color for every <p> element that is the second p element of its parent, counting from the last child:

p:nth-last-of-type(2){
background:red;
}

</p>

41
Q

:nth-of-type()

A

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
Q

:only-of-type

A

Specify a background color for every <p> element that is the only child of its type, of its parent:

p:only-of-type{
background:#ff0000;
}

</p>

43
Q

:only-child

A

Specify a background color for every <p> element that is the only child of its parent:

p:only-child{
background:#ff0000;
}

</p>

44
Q

:optional

A

Select and style only if the element does not have a “required” attribute:

input:optional{
background-color:yellow;
}

45
Q

:out-of-range

A

Select and style only if the value of the element is “out of range”:

input:out-of-range{
border:2px solid red;
}

46
Q

::placeholder

A

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
Q

:read-only

A

Select and style only if the input element is “readonly”:

input:read-only{
background-color:yellow;
}

48
Q

:read-write

A

Select and style only if the input element is not “readonly”:

input:read-write{
background-color:yellow;
}

49
Q

:required

A

Select and style only if the element has a “required” attribute:

input:required{
background-color:yellow;
}

50
Q

:root

A

Set the background color for the HTML document:

:root{
background:#ff0000;
}

51
Q

::selection

A

Make the selected text red on a yellow background:

::selection{
color:red;
background:yellow;
}

52
Q

:target

A

Highlight active HTML anchor:

:target{
border:2px solid #D4D4D4;
background-color:#e5eecc;
}

53
Q

:valid

A

Select and style only if the value of the element is valid:

input:valid{
background-color:yellow;
}

54
Q

:visited

A

Select and style visited links:

a:visited{
color:pink;
}

55
Q

element element

A

Select and style every <p> element that is inside </p><div> elements:

div p{
background-color:yellow;
}

</div>

56
Q

element,element

A

Select and style all <h2> elements AND all </h2><p> elements:

h2, p{
background-color:yellow;
}

</p>

57
Q

element.class

A

Select and style every <p> element with the class “intro”:

p.intro{
background-color:yellow;
}

</p>

58
Q

element

A

Select and style all <p> elements:

p{
background-color:yellow;
}

</p>

59
Q

*

A

Select all elements, and set their background color to yellow:

*{
background-color:yellow;
}

60
Q

id

A

Style the element with id=”firstname”:

#firstname{
background-color:yellow;
}
61
Q

.class

A

Select and style all elements with class=”intro”:

.intro{
background-color:yellow;
}