topskill.dev
CoursesTracks
0
All courses/CSSBox Model Seed Packet Card
Layout Fundamentals
1 / 10
← CSS
○CSS Rule Style an Exhibit Card○Write Your First CSS Rule○CSS Selectors Target Exhibit Details○Target Exhibit Details○Apply CSS Three Sources○Apply CSS Three Ways○Specificity Resolve a Style Conflict○Resolve Specificity○Inheritance and the cascade✦Module Quiz
○Color Palette○Color Palette○Background Layer○Background Layer○Type Rhythm○Type Rhythm○Borders and Shadows○Borders and Shadows✦Module Quiz
●Box Model Seed Packet Card○Space a Seed Packet○Display Swap Table Labels○Arrange Swap Table Labels○Positioning Pickup Pin○Pin the Pickup Location○Sizing and Overflow○Size a Seed-Swap Notice○Sticky scroll headings✦Module Quiz
○Advanced Selectors Book Cart Sign○Target a Book Cart Sign○Pseudo-Classes Night Cart States○Style Night Cart States○Pseudo-Elements○Add a Book-Quote Mark✦Module Quiz
○Lantern Market navigation○Lantern Market navigation✦Module Quiz
○Community garden request card○Community garden request card✦Module Quiz
○Flex Direction○Flex Direction○Main-Axis Spacing○Main-Axis Spacing○Cross-Axis Alignment○Cross-Axis Alignment○Wrapping and Flex Items○Wrapping and Flex Items○Flexbox Navigation○Flexbox Navigation✦Module Quiz
○Grid Tracks○Grid Tracks○Grid Gaps○Grid Gaps○Grid Placement○Grid Placement○Responsive Grid○Responsive Grid✦Module Quiz
○River radio schedule○Harbor radio schedule✦Module Quiz
○Field note color system○Field note color system○Transforms○Rotate a Field Note○Resilient styles✦Module Quiz
○Kite festival signal○Garden festival signal✦Module Quiz
○Garden forecast○Harbor forecast○Fluid sizing○Fluid weather bulletin○Images that fit✦Module Quiz
○Seed inventory table○Tool checkout table✦Module Quiz
○Community maker profile○Maker profile sheet✦Module Quiz

Box Model Seed Packet Card

See the layers of a seed packet

This module styles a Riverside Seed Swap card. Its text, inner spacing, outline, and outer spacing are different parts of the CSS box model.

The content is the text itself. padding: 20px adds space around it inside the border. border: 4px solid #3c6e47 draws the green edge. margin: 24px 0 sets 24px above and below the packet and zero at the left and right. Two margin values read “vertical, horizontal.” The same shorthand works for padding. With four values, read clockwise: top, right, bottom, left. One value applies to all four sides. An auto horizontal margin can share remaining space on either side of a width-limited block, which is how the supplied main element is centered.

The supplied * selector matches every element. Its box-sizing: border-box makes the declared width include padding and border. Without it, the usual content-box width covers only content, so padding and border add to that width. Margin stays outside either width.

The space in .packet h1 and .packet p selects headings and paragraphs inside the packet. Those supplied rules remove the heading's top margin and paragraph's bottom margin so you can see the packet padding clearly.

Here .packet uses width: 100% to fill its parent. On a wide preview the parent is capped at 420px; the diagram uses that size. Narrower previews can make it smaller. Adjacent vertical margins can collapse together rather than add, so not every visible gap is a sum of margins.

Move the inner edge

Run. Change the packet's padding to 36px, then Run again. The text moves inward while the border-box width stays the same. Restore 20px before the exercise.

Learn more

MDN's box-model guide describes these layers in more detail.

Hint 1
1 / 1
HINT 1

Padding is inside the border; margin is outside it.

Files
  • ⋄index.html
  • ⋄style.css
Loading editor…