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.
When an element's position is absolute and no ancestors are positioned, it will be positioned relative to the ________.
- Body
- Document
- Nearest positioned ancestor
- Viewport
When an element's position is set to absolute and no ancestors are positioned (with relative, absolute, or fixed positioning), it is positioned relative to the viewport, which is the browser window. This means it's positioned in relation to the visible area of the web page.
How would you select list items that are the only child within their containing unordered list?
- :lonely-child
- :only-child
- :single-child
- :unique-child
To select list items that are the only child within their containing unordered list, you should use the :only-child pseudo-class. This targets elements that are the only child of their parent, ensuring that it's the sole element within the parent container.
Media queries using the orientation feature can detect if the device is in ______ or ______ mode.
- light, dark
- mobile, desktop
- portrait, landscape
- vertical, horizontal
Media queries with the orientation feature are used to detect whether the device is in portrait or landscape mode. This is valuable in responsive web design as it allows you to adjust the layout and styling based on the device's orientation, ensuring a better user experience.
What is the role of the calc() function in CSS?
- The calc() function is used to calculate mathematical expressions in JavaScript.
- The calc() function is used to calculate values for CSS properties by performing mathematical operations.
- The calc() function is used to create animations in CSS.
- The calc() function is used to define color calculations in CSS.
The calc() function in CSS allows you to perform mathematical operations to calculate values for CSS properties. It's useful for creating responsive layouts and defining dynamic values based on other property values. For example, you can use calc() to set the width of an element as a percentage of the parent container's width minus a fixed value.
Which property in CSS is used to align text to the center?
- align-text: center;
- center-text: horizontal;
- text-align: center;
- text-center: horizontal;
To align text to the center in CSS, you can use the text-align property and set it to the value center. This will horizontally center-align the text within its containing element.
Which CSS unit is relative to the root element's font size?
- em
- px
- rem
- vw
The rem unit in CSS is relative to the root element's font size, which makes it a practical choice for creating responsive layouts. Unlike em, which is relative to the font size of its nearest parent, rem is always relative to the font size of the root (html) element.
How do you define the number of columns in a grid layout?
- By setting the grid-template-rows property
- By specifying the grid-column-count property
- By using the grid-areas property
- By using the grid-columns property
You define the number of columns in a grid layout by specifying the grid-column-count property. This property allows you to set the exact number of columns you want in your grid, providing fine control over your layout.
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.