You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_pbs/pbs182.md
+12-14Lines changed: 12 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,13 @@ creators: [bart, allison]
5
5
date: 2026-04-11
6
6
---
7
7
8
-
*Cascading Style Sheets*, or CSS, was among the very first technologies covered in Programming By Stealth. We started our CSS explorations way back in [instalment 6](./pbs6), and by [instalment 10](./pbs10) we'd pretty much finished with the topic. The only other time we covered CSS in any depth was instalment [PBS 28](./pbs28), though we used it regularly throughout the series. We Learned the fundamentals of how CSS's works, and more importantly, why it's important to use CSS to separate the look of web apps and web sites from their semantic structure, which we'd previously learned is expressed in HTML.
8
+
*Cascading Style Sheets*, or CSS, was among the very first technologies covered in Programming By Stealth. We started our CSS explorations way back in [instalment 6](./pbs6), and by [instalment 10](./pbs10) we'd pretty much finished with the topic. The only other time we covered CSS in any depth was instalment [PBS 28](./pbs28), though we used it regularly throughout the series. We learned the fundamentals of how CSS's works, and more importantly, why it's important to use CSS to separate the look of web apps and websites from their semantic structure, which we'd previously learned is expressed in HTML.
9
9
10
10
Because our exploration of CSS never went beyond the basics, we never covered the more advanced features like so-called *CSS Variables*. Until [Bootstrap 5.3](https://getbootstrap.com/docs/5.3/getting-started/introduction/) made it impossible to achieve certain customisations without CSS variables, I'd never encountered a need to learn about CSS *'variables'*. So, I didn't make time to learn about them myself, let alone include them in this series. But now that we're about to discuss customising Bootstrap, we have a good motivation for adding them to our proverbial programming toolboxes.
11
11
12
-
While Bootstrap customisation is our reason for exploring the topic, nothing we cover in this instalment is in any way specific to Bootstrap. The features covered here are completely generic, and can be used on any of your web apps or web pages, whether or not they're styled with the help of Bootstrap.
12
+
While Bootstrap customisation is our reason for exploring the topic, nothing we cover in this instalment is in any way specific to Bootstrap. The features covered here are completely generic and can be used on any of your web apps or web pages, whether or not they're styled with the help of Bootstrap.
13
13
14
-
> **Note on the use of *'colour'* & `color` in this instalment** — as an Irish resident and proud European I make a point of writing these notes in my own voice, using my local spellings and language patterns. Specifically, that these notes are written in [Hiberno-English](https://en.wikipedia.org/wiki/Hiberno-English), or in HTML jargon, `lang="en-IE"`. This is why the descriptive parts of this blog post spell *'colour'* the European way, with a *'u'*. Computer programming languages on the other hand almost universally written in American English (or `en-US`), and that very much includes CSS. Every colour-related identifier in the CSS specification uses the American spelling, without the `u`, for example `background-color`. To avoid confusion, I choose to adopt the same American spelling for all my own identifiers when writing CSS. This is why all code snippets in these notes use `color`.
14
+
> **Note on the use of *'colour'* & `color` in this instalment** — as an Irish resident and proud European, I make a point of writing these notes in my own voice, using my local spellings and language patterns. Specifically, that these notes are written in [Hiberno-English](https://en.wikipedia.org/wiki/Hiberno-English), or in HTML jargon, `lang="en-IE"`. This is why the descriptive parts of this blog post spell *'colour'* the European way, with a *'u'*. Computer programming languages, on the other hand almost universally written in American English (or `en-US`), and that very much includes CSS. Every colour-related identifier in the CSS specification uses the American spelling, without the `u`, for example,`background-color`. To avoid confusion, I choose to adopt the same American spelling for all my own identifiers when writing CSS. This is why all code snippets in these notes use `color`.
15
15
{: .aside}
16
16
17
17
## Matching Podcast Episode
@@ -64,7 +64,7 @@ The reason properties are defined as having a *default* inheritance behaviour ra
64
64
65
65
## The Problem to be Solved
66
66
67
-
The feature colloquially referred as *CSS variables* was added to CSS to solve a common problem that we have been side-stepping by using Bootstrap's default styles for all our web apps — consistency without code repetition!
67
+
The feature colloquially referred to as *CSS variables* was added to CSS to solve a common problem that we have been side-stepping by using Bootstrap's default styles for all our web apps — consistency without code repetition!
68
68
69
69
We've achieved consistency by simply applying the Bootstrap CSS classes to our various elements, and trusting that Bootstrap's style sheet will keep all our spacing, typography, and colours consistent, which of course it does.But had we been developing our own custom styles from scratch, we'd be all to familiar with this problem!
70
70
@@ -74,15 +74,15 @@ Clearly, we need to be able to define some form of **reusable named values** in
74
74
75
75
## How CSS Implements 'Variables' — CSS Custom Properties
76
76
77
-
CSS is not a programming language in the traditional sense — you don't execute CSS code to achieve tasks! Instead, it's a kind of markup language for defining how HTML content should look. Given this context, it shouldn't be surprising that CSS's approach to *variables* is nothing like what we've seen in traditional programming languages like Javascript and Bash.
77
+
CSS is not a programming language in the traditional sense — you don't execute CSS code to achieve tasks! Instead, it's a kind of markup language for defining how HTML content should look. Given this context, it shouldn't be surprising that CSS's approach to *variables* is nothing like what we've seen in traditional programming languages like JavaScript and Bash.
78
78
79
79
The way CSS implements the concept of custom named values is by extending its existing concept of style properties. Simply put, we can **invent our own CSS style properties**! The properties we invent behave just like the regular CSS style properties we use all the time like `color`, `font-family`, `border-width`, etc.
80
80
81
81
However, because we're inventing these properties ourselves, they have no direct visual effect. For them to become somehow visible, we need to reference them from within style declarations for the traditional CSS style properties. In effect, we say *set the background colour to be the same as the local value for this invented property*.
82
82
83
83
Local value? Like every other CSS style property, every HTML element gets its own internal instances of our invented properties, and, just like with traditional style properties like `font-family`, the values for our invented properties can cascade through our document.
84
84
85
-
In other words, **CSS *variables* behave like CSS properties**, not like Javascript variables, because they actually **are** CSS style properties!
85
+
In other words, **CSS *variables* behave like CSS properties**, not like JavaScript variables, because they actually **are** CSS style properties!
86
86
87
87
Finally, **custom CSS properties cascade by default**.
88
88
@@ -102,13 +102,13 @@ The rules are simply:
102
102
103
103
In effect that means **case-sensitive dash-delimited names** of the form `--my-variable-name`.
104
104
105
-
By convention, custom properties are named following the same approach as the standard CSS style properties — full words in all lower case, separated with dashes. You could use upper-case letters if you wished, but your properties would look very unusual and other developers would probably get cranky with you!
105
+
By convention, custom properties are named following the same approach as the standard CSS style properties — full words in all lower case, separated with dashes. You could use upper-case letters if you wished, but your properties would look very unusual, and other developers would probably get cranky with you!
106
106
107
107
### Assigning and Using Custom CSS Property Values
108
108
109
109
Other than their funny names, you assign values to custom properties just like you would for the traditional CSS properties — that is to say, using style declarations.
110
110
111
-
To set the `color` property to `DarkBlue` for all top-level headings we would use:
111
+
To set the `color` property to `DarkBlue` for all top-level headings, we would use:
112
112
113
113
```css
114
114
h1 {
@@ -153,7 +153,7 @@ What does that mean?
153
153
Imagine we have the following HTML code:
154
154
155
155
```html
156
-
<p>This is the partent tag, <em>and this is a child tag</em>.</p>
156
+
<p>This is the parent tag, <em>and this is a child tag</em>.</p>
157
157
```
158
158
159
159
Then imagine we have the following style sheet:
@@ -366,15 +366,13 @@ The `calc()` function expects to be passed a list of **space-delimited arguments
366
366
367
367
As an example, let's look at a simple implementation of the concept of using ratios of abase spacing size for all paddings and spacings:
368
368
369
-
**BART I will probably interrupt you the instant you start this because you use root and not @property. You explained them both, but you didn't tell us why you use one sometimes and another the other time. **
370
-
371
369
```css
372
370
/* set a base spacing value */
373
371
:root {
374
372
--space: 1rem; /* the width of one em-dash at the document root's font size (root-em)*/
375
373
}
376
374
377
-
/* calculate margins and paddings for the the document */
375
+
/* calculate margins and paddings for the document */
378
376
body{
379
377
margin: 0px;
380
378
padding: 0pxvar(--space) 0pxvar(--space); /* top left bottom right*/
@@ -579,7 +577,7 @@ blockquote {
579
577
}
580
578
```
581
579
582
-
As explained previously, simply updating the value of the custom property has no visible effect, we need to use that value in astyle declaration that has a high enough specificity to *'win'* over the less specific declaration that has already set the font family to the default value of the `--body-font` custom property at the `<body>` level.
580
+
As explained previously, simply updating the value of the custom property has no visible effect. We need to use that value in astyle declaration that has a high enough specificity to *'win'* over the less specific declaration that has already set the font family to the default value of the `--body-font` custom property at the `<body>` level.
583
581
584
582
These two things can be done within a single css statement, if, and only if, the custom
585
583
property is updated **before** it's new value is used:
@@ -819,7 +817,7 @@ You'll find the JavaScript powering the widget at the bottom of the file. It imp
819
817
2. Tune the readability of the UI by adjusting the borders, spacings, and font sizes, being sure to use custom CSS properties to make the various relevant values adjustable.
820
818
3. Enhance the usability of the UI by:
821
819
1. Choosing an appropriate font, background colour, and text colour for the display textbox to make it look like what it is — capture each of those three things in custom properties.
822
-
2. Choosing colours for both the buttontext and background. It's important that your UI makes a visual distinction between the three types of button (number, operator & action). How you choose to do that is up to you, but you should make the specifics of your choice customisable with custom properties.
820
+
2. Choosing colours for both the buttontext and background. It's important that your UI makes a visual distinction between the three types of buttons (number, operator & action). How you choose to do that is up to you, but you should make the specifics of your choice customisable with custom properties.
0 commit comments