CSS Lab 2 — Box model
Edit css/styles.css to perform experiments. Use DevTools →
Computed box model to read padding / border / margin / content sizes.
Exercise: inspection
Open DevTools → inspect the Computed box
Movie title
Short tagline showing how text flows inside padding.
A paragraph to create height; used to inspect vertical padding and margin.
Read moreExercise: box-sizing
We have two identical boxes configured with:
.box {
width: 12.5rem; /* 200px */
padding: 1.25rem; /* 20px */
border: 0.3125rem solid #4b9; /* 5px */
border-radius: 0.375rem;
background: #fff;
}
Exercise: width units (px, %, vw)
Compare fixed, relative, and viewport-based widths. Resize the window and watch how they behave.
Exercise: min/max-width & wrapping
Keep content readable by limiting line length with
min/max-width.
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium possimus quisquam dolore maiores cupiditate repellat numquam ratione illum minima similique. Quis, deleniti. Accusamus, doloribus reiciendis? Perspiciatis culpa eveniet voluptates?
Exercise: height & overflow
Explore how fixed heights can cause overflow and how to control it.
Long content… Long content… Long content… Long content… Long content…
Long content… Long content… Long content… Long content… Long content…
Long content… Long content… Long content… Long content… Long content…
Exercise: Quirky Margins
Observe vertical margin behavior. Read the short tasks and record what you see.
Adjacent siblings
Box 1 has a margin bottom defined, Box 2 has a margin top defined.
- How large is the gap between Box 1 and Box 2. Is it 60px or 40px or?
Parent & first-child
Margins can behave unexpectedtly in specific edge-cases..
Exercise: border vs outline
Discover the differences between border and outline.
Bonus: Building a “polaroid” frame
Use margins, padding and borders to create a "photo frame".
The end result is shown in this image below:
A tiny sunset
-
Use
linear-gradientand fixedheightto create a "sunset" photo. - Add a border to the photo.
- Update the caption by centering the text, decreasing the font-size slightly and adding a margin.
- Add a padding to the parent container.