Performance: Common UI use cases
Common UI patterns affect page load speed, rendering smoothness, and user interaction responsiveness.
Jump into concepts and practice - no test required
nav ul { display: flex; gap: 1rem; } nav ul li { flex: 0 0 auto; }nav ul { display: block; } nav ul li { float: left; width: 100px; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Float-based layout | Moderate | Multiple on resize | High | [X] Bad |
| Flexbox layout | Moderate | Single on resize | Medium | [OK] Good |
| Display toggle for visibility | Low | Reflow on toggle | Medium | [X] Bad |
| Opacity toggle for visibility | Low | No reflow | Low | [OK] Good |
| Grid layout | Moderate | Single layout pass | Medium | [OK] Good |
primary?button elements with class primary. .button primary is invalid syntax. #primary button selects buttons inside an element with id primary. button#primary selects button with id primary.button {
background-color: blue;
color: white;
}
button:hover {
background-color: green;
}:hover selector changes styles when the mouse is over the element..card {
width: 300px;
margin: 0 auto 0 auto;
display: inline-block;
}
What is the main reason it fails?display: inline-block makes the element inline-level, so margin: 0 auto does not center it.flex-wrap: wrap and justify-content: space-between. Grid with fixed columns won't wrap well. Floats and inline-block are outdated and less flexible.