Skip to content

Conversation

@rpbourret
Copy link
Collaborator

The basics

The details

Resolves

Adds a CSS codelab.

Proposed Changes

Adds a CSS codelab in the form of a Markdown file, PNG screenshots, and starter and completed code.

Reason for Changes

We need a CSS codelab.

Test Coverage

Manually tested.

Documentation

Included.

Additional Information

@BenHenning
Copy link
Collaborator

I think @maribethb is planning to look at this, so de-assigning myself unless I'm told that I need to review this.

@BenHenning BenHenning removed their assignment Dec 10, 2025
### What you'll need

- A browser
- Basic knowledge of HTML, CSS, and JavaScript.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add: Basic knowledge of SVG elements.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

others use `fill` and `stroke`. This is because `background-color` and `color`
apply to HTML elements, like the `<div>` used by the toolbox, and `fill` and
`stroke` apply to SVG elements, like the `<path>` used by the flyout background.
(An exception to this is the `<svg>` element, which uses `background-color` and
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's confusing to say that fill and stroke apply to SVG elements, except for the <svg> element.

How about:

"An exception to this is the top-level <svg> element that contains Blockly, which uses background-color and color."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

### The !important declaration

You might have also noticed that some rules use an `!important` declaration
while others don't. This is because Blockly sets colours in several different
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This is because Blockly sets colours in several different ways" -> "This is because Blockly dynamically creates and sets colours of some elements based on block definitions."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this comment. The point here is that Blockly uses several different techniques to set colours and you have to understand which one is being used in order to override it. It doesn't matter if the colour was set dynamically or statically -- the user is looking at/overriding the end state. Also, this applies to all colours, not just those used in blocks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, the current wording is fine.

cases, you will need to
[search Blockly's rules](https://developers.google.com/blockly/guides/configure/web/appearance/css#blockly_css_rules).

A simpler rule of thumb is that if your rule doesn't work, you probably need an
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof. I'd prefer not to give this advice, since CSS best practices involve not using !important

I would prefer no advice here, just the listing of different ways that styles are set (as above).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

```

The `categorystyle` property assigns a style that is used by a theme. Because
you're not using themes to assign category colours, replace this with a
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Because you're not using themes to assign category colours, you don't need the categorystyle property. Delete it and add a cssConfig property that [...]"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

presentation attributes, which are easily overridden.

(Note that different renderers use different numbers of `<path>` elements to
draw a block. The renderer used in this codelab (thrasos) uses a single `<path>`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize Thrasos and Zelos, and add a link to the renderer documentation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps move this note to the top of the block colouring section, since you also mention renderer-specific changes in the next subsection.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added link and capitals. Moved the more general part of the note to the start of the block fill and stroke section.

}
```

Refresh your page and notice the change in colour:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"and notice that the workspace background is now orange:"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

```

To see your new colours, reload the web page, drag the `if do` block out again,
and reopen the mutator. You should see something like this:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"You should see that the mutator workspace background colour is orange, matching the main workspace background:"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
```

Now reload your page. You should see a Blockly editor with Halloween colours:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"You should see a Blockly editor with a yellow toolbox and yellow scrollbars:"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
```

Refresh your web page and open the **Logic** category. You should see something
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"You should see that the logic blocks are now rendered in an autumnal brown instead of blue:"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

@rachel-fenichel rachel-fenichel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@rachel-fenichel rachel-fenichel merged commit 75d7564 into RaspberryPiFoundation:main Dec 16, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants