Suppose you want to target every third list item in a list. Which CSS pseudo-class will you use?
- :every-third
- :nth-child(3n)
- :nth-item(3n)
- :third-child
To target every third list item in a list, you should use the :nth-child(3n) pseudo-class. This selects elements that are at positions that are multiples of 3 within their parent.
How can you ensure that text remains visible during webfont load?
- Reduce the font file size
- Set "font-display: swap;" in your CSS
- Use "font-style: italic;" for fallback fonts
- Use JavaScript to handle font loading
To ensure that text remains visible during web font loading, you can set the "font-display" property in your CSS to "swap." This tells the browser to use a fallback font until the web font is fully loaded and ready to display, preventing a "FOUT" (Flash of Unstyled Text) for web fonts.
Animating properties like opacity and transform is considered more performant because they don't trigger ________ in most browsers.
- redraws
- relayouts
- repaints
- rerenders
When certain properties like opacity and transform are animated, they are considered more performant because they typically don't trigger relayouts or "reflows" in most browsers. Relayouts are costly in terms of performance and can significantly slow down animations.
The animation-direction property can be set to ________ to make the animation play in reverse direction.
- alternate
- backwards
- paused
- reverse
The "animation-direction" property in CSS allows you to control the direction of an animation. Setting it to "reverse" will make the animation play in the reverse direction, essentially rewinding the animation.
How can you target an ordered list and its list items in a single CSS selector?
- ol + li { ... }
- ol / li { ... }
- ol li { ... }
- ol, li { ... }
To target both an ordered list (ol) and its list items (li) in a single CSS selector, you should use "ol li" without any comma or additional characters. This selector will apply styles to all li elements within an ol element.
Which value of animation-fill-mode ensures the animation's styles are applied before the animation begins?
- backwards
- both
- forwards
- none
The value of animation-fill-mode that ensures the animation's styles are applied before the animation begins is backwards. When you set animation-fill-mode to backwards, the element retains the styles of the first keyframe until the animation begins. This can be useful to set initial styles before the animation starts.
In a responsive design, you have a sidebar that should stick to the top after scrolling past its initial position but stop sticking when it reaches the footer. Which positioning property would you apply to the sidebar?
- Absolute
- Fixed
- Relative
- Sticky
To create a sidebar that sticks to the top after scrolling past its initial position but stops sticking when it reaches the footer, you should apply the "position: sticky" property. It maintains the element's natural position until a specified scrolling threshold is reached, and then it behaves as if it were fixed.
What does the "forwards" value for the "animation-fill-mode" property do?
- It makes the animation continue in its final state after completion.
- It repeats the animation indefinitely.
- It reverses the animation direction.
- It sets the animation to be paused.
The "forwards" value for the "animation-fill-mode" property makes the animation continue in its final state after completion. It ensures that the final keyframe of the animation is retained as the end state even after the animation completes.
The em unit in CSS is relative to the ________.
- Body background color
- Font-size of the parent element
- Screen width
- Width of the border
The em unit in CSS is relative to the font-size of the parent element. It's a relative unit, making it valuable for creating scalable and responsive designs. When you set an element's font-size in ems, it's relative to its parent's font-size.
How can you ensure that a CSS transition applies only when a specific property changes?
- By using the transition property without specifying any properties.
- By using the all value for the transition-property property.
- By creating a separate CSS class for each property you want to transition.
- By defining multiple transition rules for each property.
To ensure that a CSS transition applies only when a specific property changes, you can use the transition-property property and set it to "all." This means the transition will be applied to all properties that change. If you want to target specific properties, you can list them individually in the transition-property property. Using "all" is a convenient way to apply transitions to all changing properties.