CSS Styling and Layout Practice Quiz (23 questions)

All questions and answers

1. What is the primary role of CSS in a web document?

To define the document’s content and structure
To store and retrieve data for the document
To describe the document’s visual presentation
To execute application logic in the browser

To describe the document’s visual presentation

Explanation

CSS describes how a document is presented, while HTML supplies its content. Confusing CSS with HTML overlooks the distinction between styling and document content.

2. A developer wants to place CSS rules in the same HTML document but separate from the elements they style. Where should the rules go?

In an external stylesheet linked to the file
In a style attribute on each element
In the HTML document’s content elements
Inside a style element in the document

Inside a style element in the document

Explanation

CSS in a style element is internal CSS, placed in the same document apart from the styled elements. A style attribute instead places inline CSS directly on an element.

3. Which selector targets elements with the class name `myClass`?

`myClass`
`#myClass`
`*myClass`
`.myClass`

`.myClass`

Explanation

A class selector begins with a period, so `.myClass` targets elements assigned that class. The hash-prefixed form is an ID selector, not a class selector.

4. Which CSS property changes the foreground color of text?

`text-background`
`font-color`
`color`
`background-color`

`color`

Explanation

The `color` property sets foreground color, including text color. `background-color` changes the background instead, which is the most likely property to confuse with it.

5. A paragraph is inside a narrow container on the left side of a page. What does `text-align: right` do to the paragraph’s text?

Aligns it with the right edge of the entire page
Changes the paragraph’s direction to right-to-left
Aligns it with the right edge of its parent container
Moves the paragraph itself to the right of its parent

Aligns it with the right edge of its parent container

Explanation

`text-align: right` aligns text against the right side of the paragraph’s parent element. It does not position the paragraph relative to the whole page.

6. Which declaration sets text to a heavy weight using a numeric value?

`text-align: 700;`
`font-weight: 700;`
`font-size: 700;`
`font-family: 700;`

`font-weight: 700;`

Explanation

`font-weight` controls text weight and accepts numeric values from 100 to 900, so 700 is a valid choice. `font-size` controls text size rather than weight.

7. Which sequence lists the four regions of the CSS box model from the inside outward?

Content, padding, margin, border
Padding, content, margin, border
Content, border, padding, margin
Content, padding, border, margin

Content, padding, border, margin

Explanation

The box model places content inside padding, then the border, with margin outside the border. Padding and margin are easy to confuse, but padding is inside the border rather than outside it.

8. With the default CSS box sizing behavior, what area does an element's declared `width` and `height` specify?

The border and content together
The margin and content together
The content area
The padding and content together

The content area

Explanation

By default, declared width and height set the dimensions of the content area. The padding and border are not included in those dimensions under the default behavior.

9. A navigation link needs to remain in the text flow while accepting padding and margins. Which display value best fits this need?

none
inline-block
block
inline

inline-block

Explanation

An inline-block element stays in the inline flow while allowing margin and padding. A plain inline element does not accept margin or padding as described, while a block element takes the available width.

10. An element is hidden, but the layout should preserve the space it occupied. Which CSS value should be used?

display: none
visibility: hidden
position: absolute
opacity: 0

visibility: hidden

Explanation

`visibility: hidden` hides the element while reserving its space in the layout. `display: none` removes it from document flow, so its space is not preserved.

11. A child element has `width: 33%`; in the common case, which dimension determines that percentage?

A fixed pixel reference independent of its parent
The corresponding width of its parent
The browser viewport width
The child element's font size

The corresponding width of its parent

Explanation

A percentage width is commonly calculated relative to the corresponding dimension of the parent element. A fixed pixel width, unlike a percentage width, is not relative to the parent.

12. A paragraph has a font size of `2em` and padding of `1em`. Which font-size references determine those two lengths, respectively?

The viewport size for the paragraph font; the parent's font size for its padding
The paragraph's own font size for both lengths
The parent's font size for the paragraph font; the paragraph's own font size for its padding
The parent's font size for both lengths

The parent's font size for the paragraph font; the paragraph's own font size for its padding

Explanation

For font size, `em` is relative to the parent element's font size; for padding, it is relative to the same element's font size. Treating both values as relative to the parent overlooks this context-dependent distinction.

13. What does the CSS `position` property determine?

How an element's border is drawn
How an element's content is sized
How an element is positioned in the document
How text inside an element is aligned

How an element is positioned in the document

Explanation

The `position` property determines how an element is positioned in a document. Content sizing and border appearance are controlled by different CSS properties.

14. A rule sets `top: 12px` on an element, but the element remains in its normal position. Which explanation fits if its `position` value is `static`?

Static positioning measures `top` from the viewport, while relative positioning measures it from the parent
Static positioning removes the element from flow, while relative positioning keeps it in flow
Static positioning responds to `top` only when a z-index is also set
Static positioning ignores `top`, while relative positioning responds to it

Static positioning ignores `top`, while relative positioning responds to it

Explanation

Static positioning is the default and ignores offsets such as `top`; relative positioning responds to those properties relative to the element's own position. Measuring an offset from the viewport describes fixed positioning, not static positioning.

15. Which description best characterizes Flexbox as a layout method?

It positions items relative to the browser viewport
It layers items along the depth axis without arranging rows or columns
It arranges items along one dimension, in a row or a column
It arranges items in a two-dimensional grid of rows and columns

It arranges items along one dimension, in a row or a column

Explanation

Flexbox is a one-dimensional layout method that arranges items in rows or columns. A two-dimensional grid is a distinct layout approach that organizes items across both rows and columns.

16. What must be set on a container to use the flex layout model for its children?

`justify-content: center`
`display: flex`
`align-items: stretch`
`flex-direction: row`

`display: flex`

Explanation

Setting the container's `display` property to `flex` establishes the flex model. Properties such as `flex-direction` and `justify-content` control aspects of an already established flex layout.

17. In a flex container, which pairing correctly matches the alignment properties to their axes?

`justify-content` aligns an individual item; `align-items` sets the main-axis spacing
`justify-content` sets item direction; `align-items` controls space around cross-axis content
`justify-content` aligns along the cross axis; `align-items` aligns along the main axis
`justify-content` aligns along the main axis; `align-items` aligns along the cross axis

`justify-content` aligns along the main axis; `align-items` aligns along the cross axis

Explanation

`justify-content` aligns items along the main axis, while `align-items` aligns them along the cross axis. The cross-axis space between and around content is controlled by `align-content`, not by `justify-content`.

18. How can a CSS media query support a responsive layout?

By applying styles when conditions such as viewport width or orientation are met
By converting an element into a flex container whenever its content grows
By applying a three-dimensional transformation when the page is resized
By defining keyframe states that change an element over a fixed duration

By applying styles when conditions such as viewport width or orientation are met

Explanation

A media query applies styles based on conditions such as viewport width or orientation, allowing a layout to respond to the viewing context. Keyframes define animation states rather than deciding when responsive styles apply.

19. A rule uses `@media (min-width: 600px)`. Which viewport widths satisfy this condition?

Widths of 600 pixels or greater
Widths below 600 pixels
Widths of 600 pixels or less
Widths of exactly 600 pixels

Widths of 600 pixels or greater

Explanation

The `min-width` condition matches widths at or above 600 pixels. An exact-width query matches only a viewport that is precisely 600 pixels wide.

20. What does a CSS transition control when an element changes state?

How the element changes between the two states over time
Which viewport conditions cause responsive styles to be applied
Which keyframe percentages define the element’s intermediate states
How the element is rotated or scaled in two or three dimensions

How the element changes between the two states over time

Explanation

A transition specifies how an element changes from one state to another over a period of time. Keyframe percentages define states for an animation, rather than a transition between two states.

21. Which CSS property applies two-dimensional or three-dimensional transformations to an element?

The `transition` property
The `transform` property
The `@media` rule
The `animation` property

The `transform` property

Explanation

The `transform` property applies two-dimensional or three-dimensional transformations to an element. The `transition` property controls how changes between states unfold over time.

22. A visual effect must pass through several states defined at specific keyframes. Which CSS feature best fits this requirement?

A transform that changes an element’s two- or three-dimensional appearance
A media query that applies styles at specified viewport widths
A CSS transition between two element states over time
A CSS animation using keyframes and animation properties

A CSS animation using keyframes and animation properties

Explanation

CSS animations use keyframes and animation properties to animate elements through defined states. A transition instead describes how an element changes between two states.

23. Which rule can define CSS animation states at the beginning, midpoint, and end of an animation?

A `@keyframes` rule with stops at 0%, 50%, and 100%
A `@media` rule with conditions at 0px, 50px, and 100px
A `transition` declaration with three duration values
A `transform` declaration with three percentage values

A `@keyframes` rule with stops at 0%, 50%, and 100%

Explanation

A keyframes rule can specify animation states at percentage points such as 0%, 50%, and 100%. Media-query values describe conditions for applying styles, not progress through an animation.

Study with flashcards

Lock in the answers with 57 flashcards on CSS Styling and Layout.

What does CSS describe in a document?

The document’s style.

What three ways can CSS be included in an HTML document?

Inline on an element, in a `<style>` element, or in an external stylesheet.

Which symbol represents the universal CSS selector?

*

See the flashcards →

Read the study guide

Go over the full study guide for CSS Styling and Layout.

Read the study guide →

Related classes

Make your own practice quizzes

Upload your class notes and Revizly writes a practice quiz with explained answers in about a minute.

Quiz maker