Performance: Why cards organize content
Using cards affects how quickly the main content appears and how smoothly users interact with grouped content blocks.
<div class='card'><img src='img.jpg' class='card-img-top' alt='Image'><div class='card-body'><h5 class='card-title'>Title</h5><p class='card-text'>Text</p></div></div><div class='card'><img src='img2.jpg' class='card-img-top' alt='Image2'><div class='card-body'><h5 class='card-title'>Title2</h5><p class='card-text'>Text2</p></div></div>
<div><h2>Title</h2><p>Text</p><img src='img.jpg' alt='Image'></div><div><h2>Title2</h2><p>Text2</p><img src='img2.jpg' alt='Image2'></div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Plain div blocks without grouping | Many separate nodes | Multiple reflows per block | High paint cost due to scattered layout | [X] Bad |
| Bootstrap cards grouping content | Fewer grouped nodes | Single reflow per card group | Lower paint cost with consistent layout | [OK] Good |
.card..container-card or .box-card are not valid Bootstrap classes.<div class="card" style="width: 18rem;">
<img src="image.jpg" class="card-img-top" alt="Sample Image">
<div class="card-body">
<h5 class="card-title">Card Title</h5>
<p class="card-text">This is some text inside the card.</p>
<a href="#" class="btn btn-primary">Click Me</a>
</div>
</div>btn btn-primary class creates a blue button, and the card groups all content in a box.<div class="card">
<div class="card-body">
<h5 class="card-title">Title</h5>
<p class="card-text">Text here</p>
</div>
<img src="pic.jpg" class="card-img-top" alt="Image">
</div>card-img-top to be placed before the card body for correct layout.card-title and card-text classes are correctly used on heading and paragraph respectively.row and col-* classes to create responsive layouts.col-lg-4 makes each card take 1/3 width on large screens, and col-12 makes them full width on small screens, stacking vertically.row with three col-lg-4 col-12 cards inside. -> Option CPass the test and this pattern moves unknown