CSS Flashcards

1
Q

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

A

A CSS rule contains two parts: a selector and a declaration.

p {
font-family: Arial;}

‘p’ is the selector and ‘font-family: Arial;’ is the declaration.

Selectors indicate which element the rule applies to. The same rule can apply to more than one element if you separate the element names with commas.

Declarations indicate how the elements referred to in the selector should be styled. Declarations are split into two parts (a property and a value), and are separated by a colon.

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

Matches an element whose class attribute has a value that matches the one specified after
the period (or full stop) symbol.

.note {} = Targets any element whose class attribute has a value of note

p.note {} = Targets only < p > elements whose class attribute has a value of note

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 tag name?

A

Using the type selector. Matching their element name.

h1, h2, h3 {} = Targets the < h1 >, < h2 >, and < h3 > elements.

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

introduction {} = Targets the element whose id attribute has a value of introduction.

Matches an element whose id attribute has a value that matches the one specified after
the pound or hash symbol.

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

What are inside of CSS declarations?

A

CSS declarations sit inside curly brackets and each is made up of two parts: a property and a value, separated by a colon. You can specify several properties in one declaration, each separated by a semi-colon.

h1, h2, h3 {
font-family: Arial;
color: yellow;}

Properties: font-family, color
Values: Arial, yellow

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

CSS Universal Selector

A

Applies to all elements in the document. * {} Targets all elements on the page.

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

CSS Child Selector

A

Matches an element that is a direct child of another.

li>a {}

Targets any < a > elements that are children of an < /a >< li >< a > element (but not other
< /a >< a > elements in the page) < /a >< /li >

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

CSS Descendant Selector

A

Matches an element that is a descendent of another specified element (not just a direct child of that element).

Targets any < a > elements that sit inside a < p > element, even if there are other elements nested between them.

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

CSS Adjacent Sibling Selector

A

Matches an element that is the next sibling of another.

h1+p {}

Targets the first < p > element after any < h1 > element (but not
other < p > elements).

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

CSS General Sibling Selector

A

Matches an element that is a sibling of another, although it does not have to be the directly preceding element.

h1~p {}

If you had two < p > elements that are siblings of an < /p >< h1 > element, this rule would apply to both.< /h1 >

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

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

A

RGB values (example: rgb(100,100,90))
Hex Codes (example: #ee3e80)
Color Names (example: DarkCyan)

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

What CSS properties make up the box model?

A

Content box: The area where your content is displayed; size it using properties like inline-size and block-size or width and height.

Padding box: The padding sits around the content as white space; size it using padding and related properties.

Border box: The border box wraps the content and any padding; size it using border and related properties.

Margin box: The margin is the outermost layer, wrapping the content, padding, and border as whitespace between this box and other elements; size it using margin and related properties.

.box {
width: 350px;
height: 150px;
margin: 10px;
padding: 25px;
border: 5px solid black;
}

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

Which CSS property pushes boxes away from each other?

A

Margin property

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

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

A

Padding property

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

What is a pseudo-class?

A

A CSS pseudo-class is a keyword added to a selector that specifies a special state of the selected element(s). For example, :hover can be used to change a button’s color when the user’s pointer hovers over it.

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

What are CSS pseudo-classes useful for?

A

Pseudo-classes let you apply a style to an element not only in relation to the content of the document tree, but also in relation to external factors like the history of the navigator (:visited, for example), the status of its content (like :checked on certain form elements), or the position of the mouse (like :hover, which lets you know if the mouse is over an element or not).

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

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

A

Pixels, percentages, ems

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
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
19
Q

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

A

The default flex-direction of a flex container is row.

20
Q

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

A

By default, flex items will all try to fit onto one line. You can change that and allow the items to wrap as needed with this property.

nowrap (default): all flex items will be on one line

wrap: flex items will wrap onto multiple lines, from top to bottom.

wrap-reverse: flex items will wrap onto multiple lines from bottom to top.

21
Q

Flex - does this value apply to all within a container?

A

No, flex is only applied directly to the child, and not the grandchild. If we want flex on all descendants, we would have to apply it to all parent elements.

22
Q

Which axis are you working with with the property justify-content?

A

The horizontal axis (main axis, depending on what is set to default by flex-direction))

23
Q

Which axis are you working with if you are using the property align-items?

A

The vertical axis (the secondary axis, depending on what is set to default by flex-direction)

24
Q

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

A

Because they are block elements. By default, block elements will vertically stack.

25
Q

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

A

Horizontal / Row

26
Q

Will the contents be contained in an element?

A

No, contents will not be contained within an element. You will have to adjust the contents within the element (CSS Layout exercise with Smash Bros. characters, the content will pay no respect to its parent)

27
Q

How do you maintain a specific shape? (i.e. images within an element or container)

A

Using hard coded values like px will prevent the size from changing as the page changes

28
Q

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

A

Static

29
Q

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

A

It moves the item it was applied to, but doesn’t affect the rest of the document flow. (Pokemon horizontal document)

30
Q

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

A

It makes the element get positioned relative to where it would be in the normal document flow.

31
Q

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

A

Surrounding elements ignore the space the absolute positioned element would have taken up. The absolute item no longer has a place in the document flow.

32
Q

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

A

The element is placed relative to where it is in its containing (parent) element, so make sure the containing element is set to relative also. It will go back to the first HTML element that is not static.

33
Q

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

A

Set position of containing element relative to the current element (Setting a non static property to the positioned element)

34
Q

What are the four box offset properties?

A

top, right, bottom, left

35
Q

What are the four components of “the Cascade”.

A
  1. Source order
  2. Inheritance
  3. Specificity
  4. !important
36
Q

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

A

In situations where a property has been declared for an element only once, this is a very straight-forward process. For instance:

p {
color: red;
}

There is no ambiguity here. Since there are no other competing styles, all p elements in the document this CSS is applied to would have a red text color.

However, it is common in CSS development to declare styling for an element on the same property multiple times throughout your stylesheet. For instance, given the following HTML:

<h1>Some News Headline</h1>

And the following CSS:

.news-headline {
font-size: 60px;
}

.medium-text {
font-size: 25px;
}
Both the news-headline and medium-text classes include a font-size property. So which style ultimately gets applied?

Source order is, simply put, the order that your CSS rules are written in your stylesheet. The styling provided for an element last in your stylesheet is the styling that will ultimately take effect. In this case the last font-size of 25px is applied.

37
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

Inheritance is the process by which certain CSS properties on a child HTML element can receive value from a parent element, if no CSS for that property is directly declared on the child element.

38
Q

List the three selector types in order of increasing specificity.

A

CLASS, COLUMN, ID (from lowest to highest)

39
Q

Why is using !important considered bad practice?

A

CSS declarations marked as important override any other declarations within the same cascade layer and origin. Although technically, !important has nothing to do with specificity, it interacts directly with specificity and the cascade. It reverses the cascade order of stylesheets.

If declarations from the same origin and cascade layer conflict and one property value has the !important flag set, the important declaration is applied no matter the specificity. When conflicting declarations from the same origin and cascade layer with the !important flag are applied to the same element, the declaration with a greater specificity is applied.

Using !important to override specificity is considered a bad practice and should be avoided for this purpose. Understanding and effectively using specificity and the cascade can remove any need for the !important flag.

USE SOURCE ORDER TO DICTATE AND SPECIFICITY

40
Q

What does the transform property do?

A

The transform CSS property lets you rotate, scale, skew, or translate an element. It modifies the coordinate space of the CSS visual formatting model.

41
Q

Give four examples of CSS transform functions.

A

matrix( ), matrix3d ( ), perspective ( ), rotate ( ), rotate3d ( ), scale( ), translate( )

42
Q

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

A

any-hover, any-pointer, aspect-ratio, color, color-gamut, color-index, device-aspect-ratio Deprecated, device-height Deprecated, device-width Deprecated, display-mode, dynamic-range, forced-colors, grid, height, hover, inverted-colors, monochrome, orientation, overflow-block, overflow-inline, pointer, prefers-color-scheme, prefers-contrast, prefers-reduced-motion, resolution, scripting, update, video-dynamic-range, width

43
Q

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

A

< meta name=”viewport” content=”width=device-width, initial-scale=1” >

44
Q

The transition property is shorthand for which four CSS properties?

A

The transition CSS property is a shorthand property for transition-property, transition-duration, transition-timing-function, and transition-delay.

45
Q

What is a breakpoint in responsive Web design?

A

The points at which a media query is introduced are known as breakpoints.

46
Q

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

There will be less width properties, px measurement needs to be exact for different devices

Maintains column size, even as the container stretches

47
Q

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

Because of the cascade facet, the source order