CSS Flashcards

1
Q

What are the names of the individual pieces of a CSS rule?

A

the selector, the declaration of the code block, and then the properties and its values.

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

In CSS, how do you select elements by their class attribute?

A

.class-name

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

In CSS, how do you select elements by their type?

A

just write their name so ex: h1, body, etc.

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

In CSS, how do you select an element by its id attribute?

A

id-name

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

Name three different types of values you can use to specify colors in CSS.

A

You can use color (name of color), the function rgb (numbers), and hex codes(#).

*HSL, HSLA and RGBA are other ways.

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

What CSS properties make up the box model?

A

Height, width, padding, border, and margin

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

Which CSS property pushes boxes away from each other?

A

Margin. It is OUTSIDE the border element

*Margin is wearing a puffy jacket

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

Which CSS property add space between a box’s content and its border?

A

Padding. It is INSIDE the border element

*Padding is gaining weight

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

What is a pseudo-class?

A

A keyword that specifies a special state of a selected element.

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

What are CSS pseudo-classes useful for?

A

They’re useful for applying a style in relation to the user or their cursor.

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

Name two types of units that can be used to adjust font-size in CSS.

A

Px, %, rem, and em

TIP: Best to use “em” for device flexibility

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

What CSS property controls the font used for the text inside an element?

A

font-family

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

What is the default flex-direction of a flex container?

A

flex-direction: row;

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

What is the default flex-wrap of a flex container?

A

flex-wrap: nowrap;

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

Why do two div elements “vertically stack” on one another by default?

A

They are block level elements, so they take up the full width of the page and push other elements down.

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

What is the default flex-direction of an element with display: flex?

A

row (left to right)

17
Q

What is the default value for the position property of HTML elements?

A

position: static;

18
Q

How does setting position: relative on an element affect document flow?

A

“position: relative” stays the same in document flow, makes the element move in relation to where it would be in normal flow. The position of surrounding elements isn’t affected.

19
Q

How does setting position: relative on an element affect where it appears on the page?

A

“position: relative” makes the element move in relation to where it would have been in normal flow. Without offset properties it just stays in the same place.

20
Q

How does setting position: absolute on an element affect document flow?

A

It is removed from the document flow. All neighboring elements view it as not existing anymore and they will fill that space up.

21
Q

How does setting position: absolute on an element affect where it appears on the page?

A

“position: absolute” makes the element move in relation to its containing element. It is taken out of normal flow.

Cody’s answer:
It gets positioned within the nearest non-static ancestor. Moves that element into a layer of the document for strictly positioned elements. They check for any neighboring elements with their position set to not static.

22
Q

How do you constrain an absolutely positioned element to a containing block?

A

Change the element container’s position to not static, usually relative.

23
Q

What are the four box offset properties?

A

top, bottom, left, and right

24
Q

What are the four components of “the Cascade”.

A

source order, inheritance, specificity, and !important rule?

25
Q

What does the term “source order” mean with respect to CSS?

A

Source order refers to the order CSS is written in the stylesheet. The the further down the list, the higher the source order.

Written from least important to most important.

26
Q

How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule?

A

Elements can inherit styling properties from their parent element.

*Not all properties can be inherited (ex: background-color isn’t inherited). Most properties that are inherited are related to font styling.

27
Q

List the three selector types in order of increasing specificity.

A
  1. Type selector
  2. Class selector
  3. ID selector

So ID > Class > Type

28
Q

Why is using !important considered bad practice?

A

It makes it difficult to debug styling. When !important is applied to an element then it takes precedence over any other styling. The only way to change styling on something with !important is with another !important or changing it with JavaScript.

It’s better practice to use better source order.

Worth noting that the CSS library Bootstrap has some styling that have !important because it’s essential to their functionality. So !important is useful when working with libraries, but not for plain CSS.

29
Q

What does the transform property do?

A

It modifies the space (coordinate plane) of an element, through functions like rotate(), skew(), translate(), etc.

30
Q

Give four examples of CSS transform functions.

A

rotate() - which rotates the element based on the input ‘deg’

translateY() - which moves an element up or down (positive values go down)

scale() - which makes an element increase or decrease in size

perspective() - which sets the distance between the user and the z=0 plane (the larger the number the further away)

31
Q

Give two examples of media features that you can query in an @media rule.

A

Min-width and color

*Note: always include media type (usually screen)

32
Q

Which HTML meta tag is used in mobile-responsive web pages?

A

viewport

*Note:
‘width=device-width’ means load page at the full width of the device

‘initial-scale=1’ means load this page at it’s normal scale, don’t downsize it

33
Q

The transition property is shorthand for which four CSS properties? Say what each one does

A

transition-property: specifies which CSS property your transition effect is applied to

transition-duration: sets the length of time a transition animation should take to complete (default value is 0s)

transition-timing-function: sets an acceleration curve so that the speed of transition can vary over the transition duration

transition-delay: specifies the duration to wait before starting a property’s transition effect when its value changes

34
Q

CSS-responsive-layout

What is a breakpoint in responsive Web design?

A

It’s the points in which a MEDIA QUERY should be introduced. The parts where the webpage ‘breaks’ or isn’t looking as intended anymore because of different screen size. Ex: image bigger than intended, or text gets squished.

*Note usually relates to width

35
Q

CSS-responsive-layout

What is the advantage of using a percentage (e.g. 50%) width instead of a fixed (e.g. px) width for a “column” class in a responsive layout?

A

Percentages are based on the parent element which means they’ll scale accordingly if the parent is shrunk. While pixels are a hard set number that don’t change with screen size.

36
Q

CSS-responsive-layout

If you introduce CSS rules for a smaller min-width after the styles for a larger min-width in your style sheet, the CSS rules for the smaller min-width will “win”. Why is that?

A

CSS source order. The latest CSS rule sets (further down the page) take priority over rule sets that are written/read before it.

So smaller media queries for min-widths should go from smallest to largest. Always use min-width. Do ascending min-width order.

*Notes: Design page to be mobile first (basically designing two pages: mobile then desktop). Never use percentages for height.