Skip to content

Commit 5559f32

Browse files
committed
feat(layout): scale site with viewport width on desktop
1 parent b079c5f commit 5559f32

1 file changed

Lines changed: 29 additions & 56 deletions

File tree

src/layouts/BaseLayout.astro

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ const ogImage = new URL("/images/logo_fallback.png", Astro.site);
9595
display: flex;
9696
flex-direction: column;
9797
gap: var(--gap);
98+
--scale: 1;
99+
transform: scale(var(--scale));
100+
transform-origin: top center;
101+
/* The transform does not shrink layout height, so pull the page bottom
102+
up by the height the scale removed. Same trick the mobile ladder used. */
103+
margin-bottom: calc((var(--scale) - 1) * 100%);
98104
}
99105

100106
.box {
@@ -110,63 +116,30 @@ const ogImage = new URL("/images/logo_fallback.png", Astro.site);
110116
.no-mobile { display: none !important; }
111117
}
112118

119+
/* ── Desktop scaling ─────────────────────────────────────────────────────
120+
The design is sized for a 1920px wide screen where 960px fills half the
121+
viewport. Smaller or high-dpi laptops (a 14in retina MacBook is only
122+
1512 css px wide) see far fewer css pixels, so the fixed 960px looks
123+
zoomed in. These steps keep the site near the same fraction of the
124+
screen it has at 1920. Steps of 0.05 instead of a continuous formula
125+
because css cannot divide two lengths into a number in Firefox.
126+
Floor of 0.75 so text stays readable on tablets and small windows. */
127+
@media (max-width: 1919px) { .layout { --scale: 0.95; } }
128+
@media (max-width: 1750px) { .layout { --scale: 0.9; } }
129+
@media (max-width: 1650px) { .layout { --scale: 0.85; } }
130+
@media (max-width: 1550px) { .layout { --scale: 0.8; } }
131+
@media (max-width: 1450px) { .layout { --scale: 0.75; } }
132+
113133
/* ── Mobile scaling ──────────────────────────────────────────────────────
114134
The site is fixed-width (960px). Rather than rebuilding the layout,
115-
we scale the whole thing down like zooming out
135+
we scale the whole thing down like zooming out. Each step only sets
136+
--scale; the transform and margin compensation live on .layout above.
116137
───────────────────────────────────────────────────────────────────────── */
117-
@media (max-width: 1020px) {
118-
.layout {
119-
transform: scale(0.9);
120-
transform-origin: top center;
121-
margin-bottom: -10%;
122-
}
123-
}
124-
125-
@media (max-width: 900px) {
126-
.layout {
127-
transform: scale(0.78);
128-
transform-origin: top center;
129-
margin-bottom: -22%;
130-
}
131-
}
132-
133-
@media (max-width: 780px) {
134-
.layout {
135-
transform: scale(0.67);
136-
transform-origin: top center;
137-
margin-bottom: -33%;
138-
}
139-
}
140-
141-
@media (max-width: 650px) {
142-
.layout {
143-
transform: scale(0.56);
144-
transform-origin: top center;
145-
margin-bottom: -44%;
146-
}
147-
}
148-
149-
@media (max-width: 540px) {
150-
.layout {
151-
transform: scale(0.46);
152-
transform-origin: top center;
153-
margin-bottom: -54%;
154-
}
155-
}
156-
157-
@media (max-width: 430px) {
158-
.layout {
159-
transform: scale(0.37);
160-
transform-origin: top center;
161-
margin-bottom: -63%;
162-
}
163-
}
164-
165-
@media (max-width: 360px) {
166-
.layout {
167-
transform: scale(0.31);
168-
transform-origin: top center;
169-
margin-bottom: -69%;
170-
}
171-
}
138+
@media (max-width: 1020px) { .layout { --scale: 0.9; } }
139+
@media (max-width: 900px) { .layout { --scale: 0.78; } }
140+
@media (max-width: 780px) { .layout { --scale: 0.67; } }
141+
@media (max-width: 650px) { .layout { --scale: 0.56; } }
142+
@media (max-width: 540px) { .layout { --scale: 0.46; } }
143+
@media (max-width: 430px) { .layout { --scale: 0.37; } }
144+
@media (max-width: 360px) { .layout { --scale: 0.31; } }
172145
</style>

0 commit comments

Comments
 (0)