Performance: Container and wrapper patterns
This concept affects page load speed and rendering by controlling layout structure and CSS complexity.
Jump into concepts and practice - no test required
%container {
max-width: 75rem;
margin-inline: auto;
padding-inline: 1rem;
box-sizing: border-box;
}
.content {
width: 100%;
background: white;
}
%container {
width: 1200px;
margin: 0 auto;
}
%wrapper {
width: 100%;
padding: 20px;
box-sizing: content-box;
}
.content {
@extend %wrapper;
background: white;
}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fixed width container with content-box padding | Low | Multiple on resize | Medium | [X] Bad |
| Responsive max-width container with border-box | Low | Single on resize | Low | [OK] Good |
container in Sass when building layouts?.wrapper class?
@mixin container {
max-width: 1000px;
margin-left: auto;
margin-right: auto;
padding: 1rem;
}
.wrapper {
@include container;
background-color: #eee;
}@mixin container {
max-width 1200px;
margin: 0 auto;
padding: 1rem;
}