|
1 | | -/* Here are some starter styles |
2 | | -You can edit these or replace them entirely |
3 | | -It's showing you a common way to organise CSS |
4 | | -And includes solutions to common problems |
5 | | -As well as useful links to learn more */ |
6 | | - |
7 | | -/* ====== Design Palette ====== |
8 | | - This is our "design palette". |
9 | | - It sets out the colours, fonts, styles etc to be used in this design |
10 | | - At work, a designer will give these to you based on the corporate brand, but while you are learning |
11 | | - You can design it yourself if you like |
12 | | - Inspect the starter design with Devtools |
13 | | - Click on the colour swatches to see what is happening |
14 | | - I've put some useful CSS you won't have learned yet |
15 | | - For you to explore and play with if you are interested |
16 | | - https://web.dev/articles/min-max-clamp |
17 | | - https://scrimba.com/learn-css-variables-c026 |
18 | | -====== Design Palette ====== */ |
19 | 1 | :root { |
20 | | - --paper: oklch(7 0 0); |
| 2 | + --color: #0056b3; |
| 3 | + --paper: oklch(98 0 0); |
21 | 4 | --ink: color-mix(in oklab, var(--color) 5%, black); |
22 | 5 | --font: 100%/1.5 system-ui; |
23 | 6 | --space: clamp(6px, 6px + 2vw, 15px); |
24 | 7 | --line: 1px solid; |
25 | 8 | --container: 1280px; |
26 | 9 | } |
27 | | -/* ====== Base Elements ====== |
28 | | - General rules for basic HTML elements in any context */ |
| 10 | + |
29 | 11 | body { |
30 | 12 | background: var(--paper); |
31 | 13 | color: var(--ink); |
32 | 14 | font: var(--font); |
| 15 | + padding-bottom: 80px; |
| 16 | +} |
| 17 | +header { |
| 18 | + text-align: center; |
| 19 | + margin-bottom: calc(var(--space) * 2); |
33 | 20 | } |
34 | 21 | a { |
35 | | - padding: var(--space); |
36 | | - border: var(--line); |
37 | 22 | max-width: fit-content; |
| 23 | + text-decoration: underline; |
38 | 24 | } |
39 | 25 | img, |
40 | 26 | svg { |
41 | 27 | width: 100%; |
42 | 28 | object-fit: cover; |
43 | 29 | } |
44 | | -/* ====== Site Layout ====== |
45 | | -Setting the overall rules for page regions |
46 | | -https://www.w3.org/WAI/tutorials/page-structure/regions/ |
47 | | -*/ |
| 30 | + |
48 | 31 | main { |
49 | 32 | max-width: var(--container); |
50 | 33 | margin: 0 auto calc(var(--space) * 4) auto; |
51 | 34 | } |
52 | 35 | footer { |
53 | 36 | position: fixed; |
54 | 37 | bottom: 0; |
| 38 | + width: 100%; |
55 | 39 | text-align: center; |
| 40 | + background: var(--paper); |
| 41 | + padding: var(--space) 0; |
| 42 | + border-top: var(--line); |
56 | 43 | } |
57 | | -/* ====== Articles Grid Layout ==== |
58 | | -Setting the rules for how articles are placed in the main element. |
59 | | -Inspect this in Devtools and click the "grid" button in the Elements view |
60 | | -Play with the options that come up. |
61 | | -https://developer.chrome.com/docs/devtools/css/grid |
62 | | -https://gridbyexample.com/learn/ |
63 | | -*/ |
| 44 | + |
64 | 45 | main { |
65 | 46 | display: grid; |
66 | | - grid-template-columns: 1fr 1fr; |
| 47 | + grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); |
67 | 48 | gap: var(--space); |
68 | | - > *:first-child { |
69 | | - grid-column: span 2; |
70 | | - } |
71 | | -} |
72 | | -/* ====== Article Layout ====== |
73 | | -Setting the rules for how elements are placed in the article. |
74 | | -Now laying out just the INSIDE of the repeated card/article design. |
75 | | -Keeping things orderly and separate is the key to good, simple CSS. |
76 | | -*/ |
| 49 | + max-width: var(--container); |
| 50 | + margin: 0 auto; |
| 51 | +} |
| 52 | + |
| 53 | +main > *:first-child { |
| 54 | + grid-column: span 2; |
| 55 | +} |
| 56 | + |
77 | 57 | article { |
78 | 58 | border: var(--line); |
79 | | - padding-bottom: var(--space); |
| 59 | + padding: var(--space); /* Apply padding all around */ |
80 | 60 | text-align: left; |
81 | | - display: grid; |
82 | | - grid-template-columns: var(--space) 1fr var(--space); |
83 | | - > * { |
84 | | - grid-column: 2/3; |
85 | | - } |
86 | | - > img { |
87 | | - grid-column: span 3; |
88 | | - } |
| 61 | + display: flex; /* Switch to flexbox for better flow */ |
| 62 | + flex-direction: column; |
| 63 | + gap: var(--space); |
| 64 | +} |
| 65 | + |
| 66 | +article img { |
| 67 | + width: 100%; |
| 68 | + display: block; /* Removes any tiny gaps under the image */ |
| 69 | +} |
| 70 | + |
| 71 | +/* This targets the content inside details to ensure it doesn't break */ |
| 72 | +details p { |
| 73 | + margin: 0; |
| 74 | + padding-top: 10px; |
| 75 | +} |
| 76 | +summary { |
| 77 | + cursor: pointer; |
| 78 | + padding: 10px; |
| 79 | + background-color: #f4f4f4; |
| 80 | + border-radius: 5px; |
| 81 | + list-style: none; |
| 82 | + font-weight: bold; |
| 83 | + summary:hover { |
| 84 | + background-color: #e0e0e0; |
| 85 | +} |
| 86 | + |
| 87 | +summary:focus-visible { |
| 88 | + outline: 2px solid var(--color); |
| 89 | + outline-offset: 2px; |
| 90 | +} |
| 91 | +} |
| 92 | + |
| 93 | +details { |
| 94 | + margin-top: 10px; |
| 95 | + padding: 10px; |
| 96 | + border: 1px solid #ddd; |
| 97 | + border-radius: 5px; |
89 | 98 | } |
0 commit comments