You're optimizing a website for better scroll performance. Which CSS property would you use to hint to the browser about an element that will change frequently?
- position: fixed;
- transform: translate3d(0,0,0);
- will-change
- z-index
To optimize scroll performance, you can use the will-change property to hint to the browser that an element will change frequently. This allows the browser to prepare for the changes and allocate resources accordingly, improving scrolling performance. While using transform: translate3d(0,0,0); can also trigger hardware acceleration, it may not be as specific or efficient as will-change. z-index and position: fixed; are unrelated to hinting to the browser about frequent changes in an element.
The BEM methodology suggests a naming convention where the block is separated from the element by a ________.
- -
- .
- :
- _
BEM (Block Element Modifier) methodology recommends using an underscore (_) to separate the block from the element in class names. This naming convention enhances code readability and helps identify the hierarchy of elements within a block. For instance, a button element inside a header block might be named header_button.
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.
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.
You are developing a website where you want to use modern CSS features not yet supported in all browsers. How can you ensure compatibility without manually writing fallbacks?
- Use a CSS preprocessor like SASS
- Employ a PostCSS plugin
- Write conditional JavaScript code
- Ignore unsupported features
To ensure compatibility with modern CSS features, you can use a PostCSS plugin like "autoprefixer" that automatically generates fallback code for unsupported features, allowing you to write modern CSS with confidence. This minimizes the need for manual fallbacks.
You are tasked with creating a list where every even item has a gray background. Which CSS selector would help you accomplish this?
- :even
- :nth-child(even)
- :nth-child(odd)
- :odd
To select every even item in a list, you should use the :nth-child(even) selector. This will apply the styling to the elements with even indices in the list, which will give them a gray background in this scenario.