CSS Flashcards

1
Q

What is specificity?

A

When there are 2 or more CSS rules that point to the same element which one wins?

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

What is the specificity order?

A

ID > CLASS > TYPE

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

+ operator

What is this called?

example:

div + p {
background-color: yellow;
}

A
  • “adjacent sibling selector”
  • paragraph that come IMMEDIATELY after any image

<div>
<p>some text</p> // NO
<p>some text</p> // NO
</div>

<div>
<p>some text</p> // NO
</div>

<p>more text</p>

// YES

<p>some text</p>

// NO

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

> operator

What is this called?

example:

div > p {
background-color: yellow;
}

A
  • “child selector”
<div>
  <p>Paragraph 1</p>  // YES
  <p>Paragraph 2</p>  // YES  
    <span>
      <p>Paragraph 3 (inside).</p>   // NO
     </span>
  <p>Paragraph 4</p>  // YES
</div>

<p>Paragraph 5</p>

<p>Paragraph 6</p>

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

“blank space operator”

What is this called?

example:

div p {
background-color: yellow;
}

A
  • “descendant selector”
  • descendant is anything within the element, even nested elements
<div>
  <p>Paragraph 1 in the div.</p>  // YES
  <p>Paragraph 2 in the div.</p>  // YES
    <span>
      <p>Paragraph 3 in the div (inside a section element).</p>  // YES
    <span>
  <p>Paragraph 4 in the div.</p>  // YES
</span></span></div>

<p>Paragraph 5. Not in a div.</p>

<p>Paragraph 6. Not in a div.</p>

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

~ operator

example)

div ~ p {
background-color: yellow;
}

A
  • “general sibling selector”
  • siblings are elements on the same (tab) level

example 1)

<p>The general sibling selector (~) selects all elements that are next siblings of a specified element.</p>

<p>Paragraph 1.</p>

<div>
<p>Paragraph 2.</p> // NO
</div>

<p>Paragraph 3.</p>

// YES
<code>Some code.</code><p>Paragraph 4.</p> // YES

example 2)

div ~ p
{
color: red;
}

<div>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>

</div>

<p>This is a paragraph.</p>

// YES

<p>This is a paragraph.</p>

// YES

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

What is the CSS Box Model?

A

Margin –> Border –> Padding –> Content

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

display inline vs inline-block?

A
  • display:inline –> top/bottom margins & paddings not respected.
  • display:inline-block –> top/bottom/margins/padding work
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

display inline-flex vs flex?

A

display: flex; –> causes the flex CONTAINER to act as display: block
display: inline-flex; –> causes the flex CONTAINER to act as display: inline-block

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

event delegation; explain it

A

if we have alot of elements handled in a similar way (alot of buttons for example), instead of assigning a handler to each of them, put a handler on their common ancestor (the container containing all the buttons)

Capture Phase:
window –> document –> html –> body –> div –> button

Target Phase

Bubble Phase:
button –> div –> body –> html –> document –> window

ex)

var container = document.getElementById('container');
container.addEventListener('click', function(event) {
  if (event.target.className == 'remove-button') {
    // do something
  }
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

EM unit

A
  • in relation to it’s parents

- ex) LI elements inside UL. each level of nesting gets 1.3em bigger

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

REM unit

A
  • “root em”
  • the root element’s font-size (in most cases the HTML element)
  • each level of nesting in a LI and UL list does “not” get bigger
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Staples of a Responsive Design

A

1) media queries

2) multiple column layout
ex)

.container {
column-count: 3;
column-width: 10em;
}

3) flexbox
4) grid
ex)

.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}

5) responsive images

img {
max-width: 100%;
}

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