Two headings can share `font-size: 2em` and still look different. That apparent CSS puzzle is a useful reminder: browsers calculate the sizes and positions that appear on screen. Understanding those calculations makes layouts easier to predict and troubleshoot. section 1.2
Listing 1.1 A heading size conundrum
CSS:
main {
font-size: 1.25em;
}
article {
font-size: 1.75em;
}
h2 {
font-size: 2em;
}
HTML:
<main>
<h2>Main Heading</h2>
<article>
<section>
<h2>Section Heading</h2>
</section>
</article>
</main>
Compare the two headings and their surrounding elements. The listing sets up a sizing puzzle; its resolution depends on the math of CSS inheritance. section 1.2
Frontend mathematics is not one large theory to master before building a page. It is a set of practical relationships used when choosing spacing, proportions, breakpoints, colors, and type sizes. CSS and JavaScript offer different ways to work with those relationships; the useful question is which calculation belongs in the task at hand. section 1.2.1 section 1.3
The calculations become easier to recognize in familiar UI work:
- CSS Grid divides a container into rows and columns, calculating track sizes from values such as `px`, `fr`, `minmax()`, and `auto`. Its two-dimensional coordinate system helps explain where items land. section 4.1
- Flexbox calculates how items grow or shrink as available space changes. Understanding that process helps explain layouts that seem unpredictable. section 5.0
- Responsive design uses viewport units and CSS functions to make layouts fluid rather than relying on a separate fixed arrangement for every device. section 6.0
- Color and typography involve relationships too: color-model conversions and accessible schemes on one hand; font size, line height, spacing, and modular scales on the other. section 7.0 section 8.0
From data to a clickable canvas shape
A canvas does not supply the built-in content structure of HTML elements. To visualize data, map numbers to geometric shapes. To respond to a click or hover, use coordinates and shape geometry to determine whether the pointer meets something drawn. section 14.1
Start with the calculation behind the behavior you need to explain. Even trigonometry becomes practical when a design calls for a circular layout, a wave effect, or motion along a curved path. The goal is not mathematical expertise for its own sake, but more deliberate, adaptable interfaces. section 9.0 section 1.4
