Performance: Hover state
Hover states affect interaction responsiveness and visual stability during user input.
Jump into concepts and practice - no test required
button:hover { background-color: #0055cc; color: white; }
button:hover { width: 120px; padding: 20px; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Changing width and padding on hover | Minimal | 1 reflow per hover | High paint cost | [X] Bad |
| Changing background-color and text color on hover | Minimal | 0 reflows | Low paint cost | [OK] Good |
:hover pseudo-class do?:hover:hover pseudo-class activates when the mouse pointer is over an element, changing its style temporarily.:hover changes style on mouse over [OK]button elements?:hover pseudo-class is used without spaces or parentheses after the selector.button:hover { ... }. Options A, C, and D have invalid spaces or characters.<div> when hovered in this CSS?div { background-color: blue; transition: background-color 0.5s; } div:hover { background-color: green; }transition: background-color 0.5s; means background color changes smoothly over half a second.div:hover changes background color to green, so on hover it transitions from blue to green smoothly.a:hover { color: red background-color: yellow }a:hover { color: red background-color: yellow } is missing a semicolon after red, which is required to separate declarations.color: red stops hover from working. -> Option Abutton to smoothly change text color to white and background to blue on hover, but only if the button is enabled (not disabled). Which CSS selector correctly targets this?:enabled pseudo-class filters enabled buttons, and :hover applies when mouse is over the element.button:enabled:hover, which is valid and applies styles only when button is enabled and hovered.:hover, selecting :enabled descendants of hovered buttons rather than the button itself. Options C and D use invalid attribute selectors for enabled state.