Performance: Block, inline, and inline-block
This concept affects how elements are sized and arranged, impacting layout calculations and rendering speed.
Jump into concepts and practice - no test required
<div class="inline-block">Item 1</div> <div class="inline-block">Item 2</div>
<div class="block">Item 1</div> <div class="block">Item 2</div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| block | Low DOM ops | Multiple reflows on size changes | Moderate paint | [!] OK |
| inline | Low DOM ops | Few reflows, but limited control | Low paint | [OK] Good |
| inline-block | Low DOM ops | Single reflow on size changes | Low paint | [OK] Good |
block applies this behavior.block -> Option Ablock class in Tailwind [OK]inline with block behaviorinline-block which does not break lineflex which is for flexbox layoutinline-block is the class that sets display to inline-block.inline-block -> Option Ainline-block class for inline-block display [OK]inline which lacks block sizingblock which breaks linehidden which hides element<div class="block bg-blue-300 p-2">Block</div> <span class="inline bg-red-300 p-2">Inline</span>
div with block class breaks line and fills width.span with inline class flows inline, so it appears next to following text if space allows.<div class="inline w-32 h-16 bg-green-300">Box</div>
inline class causes the element to behave inline, so width and height won't apply.inline is incorrect because width and height won't apply properly -> Option B<button class="?">Btn 1</button> <button class="?">Btn 2</button>
inline-block is needed.w-24 and h-10 set fixed size, p-2 adds padding, and colors style the buttons.inline-block w-24 h-10 p-2 bg-blue-500 text-white -> Option C