Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| blocks:custom_styling [2022-11-18 14:52] – [Other Custom Content] 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, |
| + | |||
| + | There’s | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | 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// directory mentioned above under “Server Configuration”. CSS may be referenced and loaded in three different ways: | To apply custom styling, first create a CSS file, placing it under the //public// directory mentioned above under “Server Configuration”. CSS may be referenced and loaded in three different ways: | ||
| Line 8: | Line 16: | ||
| * Global CSS, automatically loaded onto all Spots in a system using the // | * Global CSS, automatically loaded onto all Spots in a system using the // | ||
| - | Block-specific CSS is placed inside a block' | + | 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:// |
| + | |||
| + | Block-specific CSS is placed inside a block' | ||
| < | < | ||
| Line 14: | Line 24: | ||
| </ | </ | ||
| - | General and global CSS can be placed anywhere under the //public// directory | + | :!: **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 ===== | ||
| - | Using a plain text editor, create a file inside | + | To try this out, create a Composition Block then click the pen in the //Custom CSS URL// field and enter the following: |
| < | < | ||
| - | /* A square button */ | + | /* A square button */ |
| .Button-ctl.square> | .Button-ctl.square> | ||
| border-radius: | border-radius: | ||
| Line 27: | Line 37: | ||
| </ | </ | ||
| - | :!: Avoid using a word processor or similar program | + | Click OK to close the CSS editor. This updates |
| - | + | ||
| - | Save the file. Once this is done, you should have the following directory/file structure inside your Block server’s root directory: | + | |
| - | + | ||
| - | < | + | |
| - | /public/ | + | |
| - | </ | + | |
| - | + | ||
| - | Activate this style using the “Custom CSS URL” field found at the top level of all blocks. Here, you must specify the path to the file with a leading forward slash, as you see in the illustration below. | + | |
| - | + | ||
| - | {{ : | + | |
| - | + | ||
| - | Add some buttons to the Composition, | + | |
| {{ : | {{ : | ||
| - | The shape of the button will now be square, rather than rounded. The class name “square” in the “Custom CSS Classes” field activates | + | The CSS rule shown above has a CSS selector (the first line after the comment delimited by /* and */) that 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” |
| - | + | ||
| - | < | + | |
| - | .Button-ctl.square> | + | |
| - | </ | + | |
| - | + | ||
| - | Basically, this rule selector | + | |
| ==== Invisible Button ==== | ==== Invisible Button ==== | ||
| Line 69: | 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 120: | 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 126: | 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 146: | Line 141: | ||
| See [[https:// | See [[https:// | ||
| + | |||
| ===== Styling Text ===== | ===== Styling Text ===== | ||
| Line 166: | Line 162: | ||
| 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 // | 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 // | ||