Fundamentals Flashcards

1
Q

What is Declaration

A

Declaration is made up of a property and a value (e.g. color: black;)

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

What is Selector

A

A declaration block is preceded by a selector (e.g. body {...})

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

What is Ruleset / rule

A

Together, the selector and declaration block are called a ruleset. A ruleset is also called a rule.

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

What are at-rules

A

at-rules are language constructs beginning with an @ symbol, such as @import rules or @media queries.

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

How to include CSS file in HTML

A

<link rel="stylesheet" href="styles.css" />

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

Select all elements with class btn
Select all elements with both classes btn and primary

<button class="btn btn-primary"></button>

A

.btn
.btn.primary

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

Select element with id one

<div id="one"></div>

A

#one

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

Selector matches all div elements that are children of of the root element. What is the root element for HTML documents.

A

:root div

The :root pseudo-class matches the root element of a document, for HTM

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

Select all div elements, all elements with the class .two, and all elements with the id #three.

A

div, .two, #three

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

Select all elements with class child that are children of element with class parent including nested children.

<div class="parent">
  <div>
    <div class="child"></div> << THIS
  </div> 
</div>
A

.parent .child

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

Select all elements with class child that are children of element with class parent. Only direct children.

<div class="parent">
   <div class="child"></div> << THIS
   <div>
     <div class="child"></div>
   </div> 
</div>
A

.parent > .child

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

Selector that matches .two elements that are immediately preceded by a .one element.

<section>
  <div class="one"></div>
  <div class="two"></div> << THIS
</section>
A

.one + .two

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

Selector matches .three elements that are siblings of .one elements. There can be any number of elements between .one and .three.

<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
A

.one ~ .three

The selector doesn’t match .three elements that are not siblings of .one elements but are nested inside another element.

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

Matches all paragraphs that are preceded by an h1, h2 or h3 element.

<h1></h1>
<p></p> << THIS
<h2></h2>
<p></p> << THIS
A

:is(h1, h2, h3) + p

Without :is() you would have to repeat the same selector multiple times: h1 + p, h2 + p, h3 + p.

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

Select elements with an href attribute.

A

a[href]

The selector only checks for the presence of the attribute, not its value. So the hyperlink is matched even though the href attribute is empty.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  • Select a elements with an href attribute pointing to https://example.com
  • How to match case-insensitive URL?
A

a[href="https://example.com"]

[attr="value"i] (case insensitive)

17
Q

Select elements with an href attribute:
* starting with https://
* ending with .com
* containing string google

A

a[href^="https://"]
a[href$=".com"]
a[href*="google"]

18
Q

Match div elements where lang parameter contains en-us space separated field.

<div lang="en-us en-gb en-au">Hello World!</div>

Not:
<div class="foobarbaz"></div>

A

div[lang~="en-us"]

Use language selector in practice

The [attr~=value] selector matches all elements with the specified attribute whose value contains a list of space-separated values and one of the values is exactly value.

19
Q

What is Cascade

A

Rules to control which selector is stronger in the event of a conflict.

20
Q

Cascade algorithm stages

A
  • Position and order of appearance
  • Specificity
  • Origin
  • Importance
21
Q

Describe Specificity components and rules

A

Consists of three components: A, B, and C (represented as (A,B,C) or A-B-C):
- A: id-like specificity
- B: class-like specificity
- C: element-like specificity

Specificities are compared by comparing the three components in order: the specificity with a larger A value is more specific; if the two A values are tied, then the specificity with a larger B value is more specific; if the two B values are also tied, then the specificity with a larger C value is more specific; if all the values are tied, the two specificities are equal.

22
Q

What is inhertitance in CSS (example)

A

For example, if you set a color and font-family on an element, every element inside it will also be styled with that color and font, unless you’ve applied different color and font values directly to them.

23
Q

What are inheritance special values

A
  • You can make any property inherit its parent’s computed value with the inherit keyword.
  • The initial keyword sets a property back to that initial, default value.
  • Remembering which CSS properties are inherited by default can be hard, unset can be helpful in that context:
    • If a property is inherited by default, the unset keyword will be the same as inherit.
    • If the property is not inherited by default, the unset keyword is equal to initial.
24
Q

Select first/second/last p under divs

A
  • p:first-of-type
  • div p:nth-of-type(2)
  • p:last-of-type
24
Q

Select first/last/second/even child of p component.

A
  • p:first-child
  • p:last-child
  • p:nth-child(2)
  • p:nth-child(even)
25
Q

Insert string yo at start and end of a p element

A
  • p::after{content:"yo";}
  • p::before{content:"yo";}
26
Q

Define and use variable in CSS

A

```css
:root { –gutter: 20px; }

h1 {margin-left: var(–gutter); }
~~~

27
Q

What relative <length> units there are in CSS and what they do?

A
  • em Font size of the parent. For example: If root font size is 10px, parent is 2em and child is 2em, final size is 4em == 40px
    • rem Font size of the root element. If root font size is 10px, and child is 2rem, then it’s size is 20px
    • ch: equal to the width of a “0” character in the rendered font.
      • Example: max-width: 15ch; to limit the line length.
28
Q

What viewport relative units there are in CSS and what they do?

A
  • vw: 1% of the viewport’s width.
    independent)
  • vh: 1% of the viewport’s height.
29
Q

What is intrinsic vs extrinsic size

A
  • An image file contains sizing information, described as its intrinsic size (default). This size is determined by the image itself, not by any formatting we happen to apply.
  • When a size is given to an element (the content of which then needs to fit into that size) we refer to it as an extrinsic size.