Section 7 - Intermediate CSS Flashcards

1
Q

What’s the hierarchy for cascading style sheets types?

A
  1. External
  2. Internal <style></style>
  3. Inline style=”color: red”

From out to in.

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

What are the 4 broad categories of determining overall level of importance? (In order of importance)

A
  1. Position
  2. Specificity
  3. Type
  4. Importance
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s the first thing we look at at the very top of the cascade when thinking of position?

A

Whether a rule is at a higher or lower position in the CSS relative to other rules

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

What happens when you have 2 rules (or more) targeting the same element applying the same thing?

li {
color: red
color: blue
}

li {
color: green
}

A

The one that is lower down replaces the previous one (the lowest one overrides all styles above). Here we are looking at the category of POSITION. Specificity wise they are all element selectors.

li {
color: red
color: blue
}

li {
color: green
}

(green wins, if there wasn’t green then blue would win)

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

What is specificity?

A

How specific a selector is in terms of the elements you’re applying the CSS rule to

(the more specific the rule is, the more important it is which is why attribute and ID are the most important)

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

For specificity, what are the 4 ways we can target an element in order of importance?

A
  1. Element li {color: blue;}
  2. Class .first-class {color: red;}
  3. Attribute li[draggable] {color: purple;}
  4. ID #first-id {color: orange;} [wins]

<li>
</li>

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

What is Type in terms of order of importance in CSS? What’s their order of importance? (2)

A

The type of CSS style being applied

  1. external
  2. internal
  3. inline

3 ways we can apply CSS (external, internal, inline), the most important styles are the ones being applied via inline code because it’s the most specific, targeting only 1 element

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

What is the “Importance” category?

A

“Important” is a keyword that you can apply to any CSS rule. It overrides any other rule for that element.

color: red;
color: green !important;

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

What are the 5 ways/rules you can combine selectors? Describe what they target too.

A
  1. Group rule - apply to group
  2. Child rule - 1 level down only
  3. Descendant rule - many levels down
  4. Chaining - super specific
  5. Combining combiners
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you use the group rule?

A

Insert a comma

applies to entire group

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

How do you use the child rule?

A

right angle bracket >

applies 1 level down only

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

How do you use the descendant rule?

A

separate selectors with a space

up to many levels down

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

How do you use the chaining rule?

A

no spaces between selectors with the appropriate symbol (#, dot, etc)

super specific targeting

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

How do you combine combiners?

A

You have an ancestor on the left and a chain on the right, and can add/remove spaces or add different rules and combos

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

Inserting a space tells the selector code what?

A

It tells the code where you don’t want to apply the style (if there was no space, it would apply to all of it)

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

Elements always go where when combining combiners?

A

FIRST

h1#title.big.heading {

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

What happens when you hover over selectors?

A

You can see which element it’s selecting which can be handy

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

Why would you combine selectors?

A

for targeting very specific elements

19
Q

Combining selectors helps you avoid what?

A

cluttering the HTML by adding a bunch of classes to elements (with this you don’t need to add classes)

20
Q

What are the 4 different values used with the position property to position elements on the screen?

position: xxx;

A
  1. Static
  2. Relative
  3. Absolute
  4. Fixed
21
Q

Describe the static positioning.

A

it’s the HTML default flow (element goes to the bottom of the previous element and gets stacked)

Just like all our other elements we’ve seen

22
Q

Describe relative positioning.

A

you move the element relative to its default position

(one of the most common ones we’ll use)

23
Q

Describe absolute positioning.

A

the element moves relative to its nearest-positioned ancestor (above) OR the top left corner of the webpage if there is no positioned ancestor

24
Q

What’s a tricky thing to keep in mind about absolute positioning?

A

If you want your targeted element to be positioned relative to another item, you have to set the ancestor to have position: relative otherwise it’s going to default to positioning your targeted element relative to the top left of the web page [because it doesn’t have an ancestor]

25
Q

What is Z-index?

A

determines which elements go on top in the Z-Axis (lower numbers sit the furthest down in the layers)

26
Q

What happens to an element on the z-axis when you have it set to a position: absolute value?

A

it doesn’t fit in with everything else on the same layer even if the z-index is set to 0 because the absolute position value takes the element out of the original HTML flow and puts in on another layer [photoshop]

27
Q

What allows you to manipulate the Z-index regarding elements?

A

Elements are put on their own layer when it has the absolute position property

28
Q

How do you send an element with the absolute position back inside the HTML flow?

A

Change it to a static or relative position again

29
Q

Describe fixed positioning.

A

The element’s position is relative to the top left corner of the browser window

(scrolls with you, is located on the exact same location no matter what)

30
Q

What are the 3 properties that help you position elements?

A
  1. position
  2. top
  3. left/right
31
Q

How can you push an element further without using position?

A

you can add extra margin

margin-left: 50px for example

32
Q

Why can you add extra margin when dealing with positioning elements?

A

Position goes outside of margin in the box model (it’s separate) so we can add to the margin number to add more space

Position
Margin
Border
Padding
Width and Height

33
Q

What are the 5 properties of the box model from bottom to top?

A
  1. Width x Height
  2. Padding
  3. Border
  4. Margin
  5. Position
34
Q

What’s a tip to get a div in the middle (of another element)? (2 ways)

A
  1. Divide the “foundation” element’s width and height by 2. (If it’s a div, the top left corner will be in the middle)
  2. Set the top and left properties to 50% (If it’s a div, the top left corner will be in the middle)

If you want the element to be smack in the middle, you need to set more custom values for top and left.

35
Q

How do you create a circle using CSS? (4 steps)

A
  1. add background-color
  2. add width
  3. add height
  4. add border-radius with a value of 50%
36
Q

How would you get the precise colors for an image?

A

Inspect > More Tools > CSS Overview > Capture Overview

it’ll show you all the colors and fonts used

37
Q

What should you make sure to do before positioning elements?

A

Make sure you have all the desired elements visible/created

38
Q

What value do you give the width property if you want it to be the same width as its parent?

A

width: 100%

39
Q

You can have 3 child selectors. T or F?
ex)
.box > div > p

A

True

40
Q

In order to set the position of a (child) element relative to a parent, what do you need to do for the child element? What about the parent? (2)

A

child needs to have position: absolute
parent needs to have position: relative

41
Q

What does a paragraph element have by default that can skew positioning?

A

it has a margin that needs to be accounted for

42
Q

How do you remove a default margin from an element?

A

margin: 0

43
Q

What’s a cheat code we can use using CSS Inspector to get the specific selector for an element?

A

Chrome:
Select line of code we want to select > right click > copy > copy selector

(we can simplify it/shorten it ourselves if needed)

44
Q

Is this a valid descendant selector?

.box div div p {

A

Yes