1.6 CSS Selectors Flashcards

1
Q

What’s the purpose of CSS selectors?

A

CSS selectors let’s us target HTML
by any of its attributes or values.

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

What are 3 types of CSS attributes?

FIT

A
  • For
  • ID
  • Type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What 3 characteristics of attributes?

A

Attributes follow elements

Attributes add specificity

Attributes provide supplemental information

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

How do you target a class?

A

Use brackets on the selector

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

When you target by class, is it changing
attributes inside or outside of the class?

A

When you target by class, it only changes
those attributes with a class

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

How do you target a specific class?

A

specify the class by name

“form-contact” is a specific class within the CSS

Only this class is being targeted

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

How do you target by ID?

A

Use ID

Write specific ID name

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

How do you target by text?

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

What does the CSS rule do in this example?

A

Only input fields with values of text that receive the background color

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

How do you target a placeholder?

A

Specify placeholder

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

What is this CSS doing to the placeholder its targeting?

A

Only input fields with values of placeholder
that receive the background color

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

How do you target email field?

A

Specify email

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

What does the CSS rules do in this scenario?

A

Only input fields with value of email
that receive the background color

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

How do you target buttons with CSS attribute selectors?

A

Specify buttons

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

How do you target links?

A

use the a anchors

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

What is DRY CSS?

A

Dry stands for

Don’t repeat yourself

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

Why should you not repeat code?

A

It makes maintenance difficult

Increase style sheet,

browser works hard

Only define once

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

How to write more flexible, efficient code?

A

Create reusable attributes that can be
reapplied in needed areas without duplication

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

Why shouldn’t you use attribtue selectors?

A

Slower to interpret by developers

Slower to interpret by browsers

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

Why are reusable elements useful? Example?

A

It prevents duplication of identical code.

Example: border radius: adding a curve to border edges

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

How do you use reusable CSS snippets?

A

Create reusable class attributes

Add the classes to the HTML

Apply the class to any element that needs that style

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

In the following example, why do we have
the button attributes both joined and separated in the CSS?

A

Joined btn class: shared properties

Separated classes: unique properties of buttons

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

How do you create inline buttons on smaller devices?

A

Steps

  1. Add Media Query
  2. Add CSS
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What does this code snippet do on smaller devices?

A

It makes the buttons appear below each other,
vertically, because of the block display method.

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

When it comes to combinators, what type
of children does the > combine?

A

The > combinator targets a direct child of an element

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

What element does the + combinator target?

A

The + combinator targets an element’s immediate sibling

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

What sibling is targeted with the ~ symbol in CSS selectors?

A

The ~ combinator targets all the specified siblings that follow an element

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

Given the use of the > symbol,

What type of combinator is this example?

A

Direct child combinator

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

What does this direct combinator do to anchor links?

A

Changes the font size to 14px

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

What symbol do you use to reach an immediate sibling?

A

The + combinator targets an element’s immediate sibling

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

What symbol do you use to reach all specified siblings?

A

The ~ combinator targets all the specified
siblings that follow an element

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

In this code snippet, what is happening in this adjacent combination? Scenario: two buttons are too close to each other

A

Leaving first button flush with content and the second and subsequent buttons have proper padding

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

How much margin is being applied through this adjacent combinator?

A

First button left aligned

Second button gets the left margin of 20px.

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

What does this sibling combinator do within the CSS?

A

What this does is it targets labels, under an H1 tag; it gives them the defined CSS style specified above

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

What is first element styling within CSS?

A

It’s applying CSS style, to the first item or element in a group.

Let’s say you have a list of 10 items.

You only want to style the 1st of the 10 items.

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

What property do you use with first child styling?

A

first-child

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

What symbol do you use to separate the HTML element from the first-child element?

A

: symbol separates both

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

In the CSS example, how is the first-element being styled?

A

background color is being set to a hexadecimal color

the font color is being set to white;

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

What does the last-child element styling do as a CSS attribute?

A

If you have a group of elements together, and you only want a special style applied to the very last item of the group, the last-child attribute helps you do just that

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

What separates the last-child element from the HTML element?

A

: symbol

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

Is there a space between parent and child attributes?

A

No.

No spaces between parent/child attributes

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

What does an only-child pseudo-class achieve?

A

The :only-child CSS pseudo-class represents an element without any siblings.

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

Why would you use an :empty element?

A

Prompt user to inform there isn’t anything there

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

In what 3 scenarios would it make sense
to use a :empty element?

A

A form field or order form or login screen
where the user forgot to input information.

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

How does this :empty element benefit end user?

A

Alerts them with a red color to a field they missed filling out, giving the end user form feedback

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

What is substrings?

A

Substrings= pieces

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

What does the begins with selector do?

A

Begins with Selector matches value

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

How do you summon the begins with? (symbol)

A

^ starts the begins with element

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

In this begins with example, what is being matched?

A

The http:// is signalling what it begins with, that’s what it’s matching content for

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

What 3 things happening in this specification value?

A

In the example, it’s

  • targeting IMAGES
  • with the TITLE
  • that BEGINS WITH “product-”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

When it comes to begins with or specifications,
do you use spaces in the syntax?

A

No

No spaces used

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

How is the ends with selector helpful?

A

It helps you style things by file extensions

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

Can you name 3 extensions that would be perfect targeting options for the ends with selector?

A

.pdf

.jpg

.svg

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

What symbol is used to launch the ends with selector?

A

$ symbol starts with ends with selector

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

In this ends-with example, what is being selected?

A

images ending with .pdf

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

Based on this CSS snippet, what’s happening with the ends with selector?

A

It’s scanning for files that end with .pdf to give them an image to represent the file format of PDF.

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

What does the contain selector do?

A

It looks for the content that may contain at least one aspect of what you’re selecting for.

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

Why would you want to use the contains selector?

A

When you know the keyword or category of item you want to select specifically for styling.

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

In this example with contains selector,
what is the CSS styling doing?

A
  1. background-repeat: no-repeat;
  2. background-size: 18px 18px;
  3. padding-left: 25px;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
60
Q

What symbol do you use to initiate the contains selector?

A

* defines the contains selector

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

In this contains example, what element is being styled?

A

Image files with thumb in the file path received styling

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

What keyword is being styled with this contains selector?

A

files with lake are being styled

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

When should you use special selectors?

A

Use when you don’t have control over HTML because
of CMS limitations to access code

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

What is a use case for focus state in the context of a form?

A

A focus state use case is to draws attention to a
textbox on a form where users enter their info with colors or other styling details.

65
Q

How do you create a focus state for an input field?

A

input:focus

66
Q

How do you create a focus state for a textarea?

A

input:textarea

67
Q

How do you group focus states when the same styling applies?

A

use a comma to separate the items

68
Q

In the example where you have 2 focus states, what’s the rest of the CSS syntax to give it a specific color for the input and text area?

A

open curly braces {

color

semi-colon

ending curly braces }

69
Q

What is happening when this CSS is applied to
the focus states within the form?

A

In the example above, when this CSS is applied, it gives textboxes specified a hover effect in green to draw attention, highlighting where the user is in the form fillout process.

70
Q

What is a disable state?

A

Disable makes something unavailable, unclickable, unuseable

71
Q

What are the visual cues of a disabled state?

A

It can be styled to be grayed-out to further validate
visually that a choice is not available.

72
Q

What is the CSS for a disable state?

:disabled followed by …?

A

:disabled class

Open curly brace

background styling

semi colon

Ending curly brace

73
Q

Can you style a checkbox?

A

Yes

You have to specify it as an input type

74
Q

In this example of checkbox formatting, what 4 things is the
CSS communicating at each point?

A

What this syntax is saying

  1. Target: input
  2. Type of input = items with checkboxes
  3. When checkbox is CHECKED,
  4. Style LABEL with this CSS rules
75
Q

How do you write the checkbox specific formatting?

Part 1: remember no spaces

A

input

[

type

=

“checkbox”

]

76
Q

What’s part 2 of checkbox formatting?

You’ve specified input,
[, type, =, “checkbox”, and] all with no spaces

A

:

checked

+

label

77
Q

What’s the 3rd part of formatting a checkbox?

A

Add styling details

ex font-weight: bold;

78
Q

What is nth child selector?

A

It lets you reach any combination of child elements,
based on any position of parent element.

79
Q

In the CSS example of nth child, what’s
happening to the items in the list?

A

When (even) is specified it targets and formats based off of the order, changing only those items that are even. So 2,4,6,8, 10 will change, not the odd numbered ones.

80
Q

How do you write the syntax for nth child
for even item numbered item selection?

A

li:nth-child(even)

81
Q

How do you write the syntax for even nth child selector after you have specified li:nth-child(even) {?

A

You add styling using basic CSS syntax for styling

open curly braces, properties, values, semi-colon, ending curly braces

82
Q

Can you target odd numbered items in a list?

A

Yes, you can

you would use the (odd)

83
Q

What’s the syntax for an nth-child with odd numbers selected?

A

li:nth-child(odd)

open curly brace

styling with property: value;

ending curly brace

84
Q

Can you target a specific list item using nth-child?

A

Yes, it’s possible to target a specific number in a list

85
Q

What CSS syntax do you use to specify a
specific numbered item within a list?

A

li: nth-child(3) {
property: value;

}

86
Q

When you specify a single number within
a nth-child selection what’s happening?

A

When the expression is reduced to a single number it only targets that number from the list.

87
Q

How does from this point forward work?

A

You have base number then it applies styling based on the number you select (ex. start here then skip 2, 3, 4)

88
Q

What value does n have?

A

1

89
Q

In the following CSS snippet, what does the
from this poitn forward selection mean?

A

A value as 1 = same as N

Targets 4 and every value after receives same formatting

90
Q

How do you write the syntax for from this point forward?

Conditions of 2n and move in intervals of 3

A

li: nth-child(2n + 3) {
property: value;

}

91
Q

What is skip pattern selection?

A

Give a starting point, then an interval for
skipping to select and apply CSS styling

92
Q

In this example what does the 3 and 2 convey as instructions?

A

3 tells it where to begin

2n tells it the pattern to follow

93
Q

Based on this example, what’s happening within the row of items?

A

The styling was that it started at

Row 3 and applied the formatting every 2 rows.

94
Q

What’s the simplified way to specify styling of every 3rd item?

A

li: nth-child(3n) {
background: green;
color: white;

}

95
Q

What is the syntax for the nth-child when the
skip pattern is set to 3n simplified?

A
96
Q

Based on this negative n value example, what is it
communicating in the CSS selection process?

A

Tells it where to begin, list item 3 and then

And it formats everything that precedes it (1&2)

Top 3 items are formatted correctly

97
Q

What is the syntax for a negative n value?

A
98
Q

What is the advantage of :nth-of-type over nth-child?

A

You use the ends of type to inform the browser to focus on elements rather than list items. It can handle interruptions.

99
Q

Do nested items affect :nth-of-type?

A

No, :nth-of-type can handle interruptions
and different types of elements.

100
Q

What’s happening in this example of :nth-of-ninth?

A

This selector targets the 4th div inside the parent,

no matter what type of child elements come before it:

101
Q

Is the heading elements affecting this :nth-of-type example?

A

No. It doesn’t let headings or other DIVs in the middle of the list get in the way of targeting.

102
Q

What’s the syntax to write :nth-of-type,
as seen in the prior example?

A

div: nth-of-type(4) {
property: value;

}

103
Q

What is :nth-of-last-type doing?

A

This is a from bottom to top selectors

1 targets last row (at the very bottom) of a group.

104
Q

How do you write the syntax for a :nth-last-of-type?

A
105
Q

Why do we use nth-child, nth-of-type or :nth-of-last-type?

A

To help get around constraints in code due to CMS

106
Q

What is the root element selector?

A

It targets the highest level HTML element

107
Q

What does this CSS snippet do with the root element?

A

:root

applies styling

108
Q

How do you write the syntax for :root?

A
109
Q

Why would you use :root over HTML selector?

A

Root has higher specificity.

110
Q

Can :root be used with other languages?

A

:root can be used with SVG and other languages

111
Q

What does :root do?

A

Root targets top most element

112
Q

What does the target pseudo class do?

A

The :target CSS pseudo-class represents a unique element (the target element) with an id matching the URL’s fragment.

113
Q

When the IDs match, the :target psuedo class does what?

A

In this particular instance it applies the target formatting, when a link is clicked upon. It’s in essence creating a selection effect.

114
Q

What is the syntax to write a :target class?

A
115
Q

What is target by ID?

A

It applies styling to a specific specified ID.

116
Q

Why would you want to use target by ID?

A

It’s useful when the styles should be applied
to only 1 item in a group.

117
Q

In this example of style by ID, how is the ID being specified?

A

With the # symbol

118
Q

After specifying the ID name, how is the target written in the syntax?

A

:target with no spaces between

119
Q

What’s the full syntax of target by ID?

ID, target, css, & curly brackets

A
120
Q

When the browser sees the target by ID, what does it do?

A

The browser hones in on the specified ID, col-c, as its target, only applying it to that ID class. Upon click, target formatting is active.

121
Q

What is a NOT selector?

A

It selects everything but one item from a group.

Helps with exclusion of an item from formatting

122
Q

What element is being excluded from this :not selector?

A

It’s styling all divs, excluding div a, from styling.

123
Q

How does it know which div to exclude?

A

It’s specified by the ID, using a # symbol.

124
Q

What is the syntax to write a not selector?

A
125
Q

How do you specify that it should style
every element in a group except a button?

A

Specify type

Then submit button

126
Q

What’s the syntax to write a submit button with :not selector?

A
127
Q

How do you add padding just to elements
that follow, leaving the first element
flush with the edge of the page?

A

Use the not element to exclude first elements using first-child

128
Q

What two elements is the first-child
referring to in the example?

A

It’s referring to the first column (.col) and first link (nav a).

129
Q

How do you separate the element from the not selector?

A

: symbol

130
Q

What goes into the parenthesis for the not selector?

A

(:first-child)

131
Q

Do you need any punctuation after the parenthesis?

A

No

132
Q

What is a pseudo element?

A

A CSS pseudo-element is a keyword added to a selector that lets you style a specific part of the selected element(s)

133
Q

What does the pseudo element of :first-line do?

A

It applies styling to the first line of text within a paragraph.

134
Q

Does :first-line apply formatting to the first sentence?

A

No, just the first line of text.

135
Q
What separates the class from the
pseudo element in the syntax?
A

: colon

136
Q

What’s the full syntax for writing for
this pseudo element of :first-line?

A
137
Q

Why would you use the first-letter pseudo element?

A

To create drop letter effect, use the first-letter pseudo element.

138
Q

How do you target the class?

A

Use a . period to specify class

139
Q

How do you specify the :first-letter pseudo class?

A

:first-letter

140
Q

What’s the full syntax for the :first-letter pseudo element?

A
141
Q

Can you use :: for pseudo elements?

A

Yes, the browser will interpret :: with pseudo elements.

142
Q

Does a pseudo element appear in HTML?

A

No, pseudo elements appears in the CSS.

143
Q

What does the before pseudo element do?

A

It adds an element before the HTML, straight from the CSS.

144
Q

Why would you use the ::before pseudo element?

A

To have more styling and design options

145
Q

What is this ::before pseudo element doing?

A

It’s adding a jpg icon before the JPG in the
HTML text; it’s an icon for an image.

146
Q

What’s the full syntax for the ::before pseudo element example?

A
147
Q

Can you apply an element after another element?

A

Yes, using the pseudo element ::after

148
Q

In this ::after pseudo element example, is the image being applied before or after the text in HTML?

A

After

149
Q

How do you select the class?

A

.jpg

. indicates class

jpg class name

150
Q

What’s the syntax for the ::after pseudo element?

A

::after

151
Q

What’s the full syntax for the ::after example?

A
152
Q

What does this combination of before and after do?

A

It adds a red circle before and after a
headline element from the CSS.

153
Q

How do you specify the before and after element?

A

use ::

::before

::after

154
Q

For DRY code, how do you condense yet separate?

A

Use the same code, to condense

Use commas, to separate elements

155
Q

What is the attr function within pseudo elements?

A

The attr() CSS function is used to retrieve the value of an attribute of the selected element and use it in the stylesheet.

156
Q

How is the title retrieved using the attr function?

A

content:attr(title);

157
Q

How does the attr function work?

A

It’s retrieving information from HTML using
single usage, type, or fallback properties.

In the case of this example, it’s retrieving
the titles using title property found within a class.

158
Q

What’s the logic behind this code with attr function?

3 steps

A

How this code works

  1. First it targets the class | .d-loads
  2. Second the descendent | a::after
  3. Third the titles | content:attr(title)
159
Q
A