HTML & CSS
/Advanced
Fluid Layouts
Definition
Layouts built using relative units (like `%`, `vw`, `fr`) instead of fixed units (`px`), allowing elements to smoothly expand and contract with the browser window.
Explain Like I'm New
Instead of saying 'This box is exactly 500px wide' and hoping the user's screen is bigger than 500px, you say 'This box takes up 50% of the screen'. As the user stretches their browser, the box stretches with it like rubber.
Real World Example
Using CSS Grid with `1fr 2fr`. The layout is fluid because the columns are mathematical fractions, not rigid pixels.
Common Use Cases
- •True responsive design
- •Handling the infinite variety of Android screen sizes
Interactive Example
Interview Questions
basic
- Which unit creates a more fluid layout: `px` or `%`?
intermediate
- How do you prevent a fluid layout from stretching too far on a massive 4K monitor?