topskill.dev
CoursesTracks
0
All courses/CSSGarden forecast
Responsive Design
1 / 6
← 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

Garden forecast

The two forecast cards need to be readable on a phone and sit side by side when there is room. The supplied HTML already includes a viewport tag in <head>; it lets a phone use its own width for the layout.

In style.css, .forecast is a grid with one 1fr column by default. The @media (min-width: 40rem) rule overrides its columns only when the viewport is at least 40rem wide. repeat(2, 1fr) makes two equal columns. The cards themselves do not need to change.

Know which width you are changing

The viewport is the area where this document renders. Inside this course it is the preview iframe, not the whole browser window and not the card's width. Resize the preview pane if its divider allows it. Otherwise open the example in a separate browser page and resize that page; merely zooming the lesson text is not the same test.

rem is a length based on the root font size for ordinary properties. In media queries it uses the browser's initial font size, commonly 16px. With that default, 40rem is 640px. A min-width query includes its boundary, so this demo changes at 640px, not only above it. The nested .forecast rule comes later and overrides the earlier columns while the query matches.

Try the demo

Preview the page at a narrow and a wide width. Below 40rem the cards stack; at 40rem and above they share a row. Temporarily change 40rem to 50rem, resize again, and notice where the layout switches. Restore 40rem before moving on.

Checkpoint: You can find both .forecast rules and explain why the wider one wins only at its breakpoint. Next you will adapt a different forecast using the same pattern.

Learn more

For more examples of breakpoints and fluid layouts, see MDN's responsive design guide.

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