Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| blocks:custom_styling [2021-03-05 12:29] – Added github link back in admin | blocks:custom_styling [2026-01-19 09:47] (current) – Added note on non-latin fonts admin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Custom Styling with CSS ====== | ====== Custom Styling with CSS ====== | ||
| - | As everything in Blocks is based on standard HTML5 web technologies, | + | As everything in Blocks is based on standard HTML5 web technologies, |
| - | To apply custom | + | There’s plenty of tutorials on the web on how CSS works, so here we will only look at how to incorporate such styling |
| - | < | + | {{ :blocks: |
| - | /* A square button */ | + | |
| - | .Button-ctl.square> | + | |
| - | border-radius: 0; | + | |
| - | } | + | |
| - | </ | + | |
| - | :!: Avoid using a word processor or similar program | + | {{ :blocks:css: |
| - | Save the file. Once this is done, you should have the following directory/ | + | Find some mode examples of ready-made styles, fonts and associated test blocks found om our [[https:// |
| - | < | + | To apply custom styling, first create a CSS file, placing it under the // |
| - | /public/styles/buttons.css | + | |
| - | </ | + | |
| - | Activate this style using the “Custom | + | * Block-specific |
| + | * General CSS, that can be used from multiple block when desired. | ||
| + | * Global CSS, automatically loaded onto all Spots in a system using the // | ||
| - | {{ :blocks:custom_styling_1.png? | + | General and global CSS can be placed anywhere under the //public// directory. Avoid using a word processor or similar program to create this file, as it must be a plain text file. On MacOS you may want to use the free version of [[https:// |
| - | Add some buttons to the Composition, | + | Block-specific CSS is placed |
| - | {{ : | + | < |
| + | ~/styles.css | ||
| + | </ | ||
| - | The shape of the button will now be square, rather than rounded. The class name “square” | + | :!: **HINT**: Press the pen icon in the //Custom CSS URL// field at the top level of the block, or choose "Edit Block CSS" on the Edit menu while inside a block to create or edit such block-local CSS. |
| + | |||
| + | ===== Button Styling ===== | ||
| + | |||
| + | To try this out, create a Composition Block then click the pen in the //Custom | ||
| < | < | ||
| - | .Button-ctl.square> | + | /* A square button */ |
| + | .Button-ctl.square> | ||
| + | border-radius: | ||
| + | } | ||
| </ | </ | ||
| - | Basically, this rule selector says; look for a button control (the “.Button-ctl” part) that also has the square class applied to it (the “.square” part). When found, change the shape of its immediate child element (the “div”) according to what’s stated inside the curly braces. You can read more about CSS selectors and CSS in general [[https:// | + | Click OK to close the CSS editor. This updates the //Custom CSS URL// field with the block-local CSS just created. Add a button, then type //square// into its " |
| + | |||
| + | {{ : | ||
| + | |||
| + | The CSS rule shown above has a CSS selector | ||
| ==== Invisible Button ==== | ==== Invisible Button ==== | ||
| Line 53: | Line 61: | ||
| </ | </ | ||
| - | Again, you can see how this selects the same “.Button-ctl” in order to only target buttons, but then states an “invisible” class name instead of “square” as in the previous example. Add the two rules above to your “buttons.css” | + | Again, you can see how this selects the same “.Button-ctl” in order to only target buttons, but then states an “invisible” class name instead of “square” as in the previous example. Add the two rules above to your CSS file, click OK, and then activate this look by typing // |
| - | ==== Complex Styling==== | + | ==== Button States ==== |
| + | You may want to style a button differently when pressed or while " | ||
| + | |||
| + | ===== Complex Styling | ||
| CSS rules can become quite complex, but they also provide a great deal of flexibility for styling things. The last example shown below is for the “glossy” button. Copy and paste the following into your “buttons.css” file: | CSS rules can become quite complex, but they also provide a great deal of flexibility for styling things. The last example shown below is for the “glossy” button. Copy and paste the following into your “buttons.css” file: | ||
| Line 104: | Line 115: | ||
| </ | </ | ||
| - | Save the CSS file, reload your Blocks | + | Close the CSS editor and activate this style by typing //glossy// into the “Custom CSS Classes” field. Open a second window to act as a Spot for interacting with this block (see “Adding a Display” and “Displaying a Block” in the Getting Started chapter for details). The result should look something like this: |
| {{ : | {{ : | ||
| Line 110: | Line 121: | ||
| It is possible to apply multiple classes to a single control or other block. Just type all the desired class names into the “Custom CSS Classes” field, separated by a space. | It is possible to apply multiple classes to a single control or other block. Just type all the desired class names into the “Custom CSS Classes” field, separated by a space. | ||
| - | ==== Finding the Selectors ==== | + | ===== Finding the Selectors |
| CSS basically consists of two parts: | CSS basically consists of two parts: | ||
| Line 130: | Line 141: | ||
| See [[https:// | See [[https:// | ||
| + | |||
| ===== Styling Text ===== | ===== Styling Text ===== | ||
| Line 141: | Line 153: | ||
| * Change the style of //all// text blocks merely by overriding the .text-block class in your custom CSS. No extra CSS classes needed. This is useful when you want to override the basic look of text everywhere. | * Change the style of //all// text blocks merely by overriding the .text-block class in your custom CSS. No extra CSS classes needed. This is useful when you want to override the basic look of text everywhere. | ||
| * Change the style of all text blocks inside another block, such as a Composition, | * Change the style of all text blocks inside another block, such as a Composition, | ||
| - | * Change the style of specific text items by applying a CSS class there. See the .text-block.font-georgia style [[https:// | + | * Change the style of specific text items by applying a CSS class there. See the .text-block.font-georgia style [[https:// |
| + | * To apply custom typefaces, first obtain the appropriate font file(s) and then load those in your CSS using a [[https:// | ||
| * Change the style of specific headings (H1, H2, etc) or style variations (bold or italics). | * Change the style of specific headings (H1, H2, etc) or style variations (bold or italics). | ||
| * Loading custom fonts when called for, such as the Chicle font show in the example above. | * Loading custom fonts when called for, such as the Chicle font show in the example above. | ||
| - | :!: Fonts are available in a variety of formats. The ' | + | :!: Fonts are available in a variety of formats. The ' |
| - | You can only apply a single style file to a block. This is specified at the root level of the block. To use styles from multiple sources, combine them all into a single CSS file. | + | You can only apply a single style file to a block. This is specified at the root level of the block. To use styles from multiple sources, combine them all into a single CSS file. You can also apply a CSS file globally, making it available to all blocks without any additional effort. This is done using the // |
| + | |||
| + | ==== Using non-Latin Fonts ==== | ||
| + | If your target audience speaks a language using non-latin characters, such as japanes or korean, you need to provide the relevant fonts containing those character sets. [[blocks: | ||
| + | ===== Globally Applied Classes ===== | ||
| + | |||
| + | A few CSS classes are applied by Blocks itself under certain conditions: | ||
| + | |||
| + | * **show-cursor** is applied while an interactive element, such as a button or a slider, is shown on screen. It is is used by Blocks to show any cursor on a regular desktop browser, allowing a mouse to be used to click those elements. | ||
| + | * Any class specified by a //class// [[blocks: | ||
| + | * **tag-XXX** will be applied based on all active tags. Tags can be set in a variety of ways – see the Blocks manual for details. | ||
| + | |||
| + | :!: **NOTE**: On PIXILAB Player, the mouse cursor may be hidden permanently, | ||
| + | |||
| + | |||
| + | These classes are all applied to an outer element, so you would use those as part of a selector that looks like like this: | ||
| + | |||
| + | < | ||
| + | .tag-mytag .text-block { | ||
| + | color: blue; | ||
| + | } | ||
| + | </ | ||
| + | Note the space between // | ||
| ===== Other Custom Content ===== | ===== Other Custom Content ===== | ||
| - | Just as you placed | + | Just as you can place a custom CSS file under the server' |
| < | < | ||