The Only Time I Used Math at Work - and It wasn t What You Think
Source: Dev.to
My First “Simple” Task on the Team… Wasn’t So Simple
The requirement on paper:
Make the menu sticky and make sure it stays aligned with the content.
For most screen sizes it worked, but larger screens exposed a problem.
The Layout Looked Straightforward
- A max‑width layout.
- The sticky menu should stay aligned with the content column.
Where Things Started to Break
Ignoring large screens means ignoring real users who actually have them.
The Real Problem
Match the content width
I had to stop thinking in fixed pixel values.
At first glance it seemed simple:
x = margin‑left + padding-left + width of the content column
But the sticky menu width turned out to be the same variable x.
Breaking the Layout Down
After inspecting and resizing the screen repeatedly, I derived the following relationships:
100vw = 2y + 2P + B
where
100vw– viewport widthy– half‑width of the sticky menu areaP– paddingB– border (or any extra spacing)
The sticky menu width is also:
x = y + C1 + P
where C1 is the fixed width of the content section itself.
Solving for y:
y = (100vw - 2P - B) / 2
Plugging this back into the first equation gives the responsive width needed for the sticky menu:
x = ((100vw - P - B) / 2) + C1 + P
The Final CSS
@media (min-width: 1439px) {
.sticky {
width: calc(((100vw - 1202px - 8px) / 2) + 794px + 4px);
}
}
Final Thoughts
- Web development must consider big screens too—high‑resolution monitors are everywhere now.
- Math hides quietly in everyday front‑end work, just enough to make layouts behave.
- Sometimes being a developer means doing a little math… and honestly, that’s kind of perfect.