Merge branch 'master' of github.com:hackersanddesigners/chatty-pub

mergin heerkos print commits with new topic commit.
This commit is contained in:
كارل مبارك 2021-07-07 16:53:39 +02:00
commit 079dc83150

View file

@ -1,8 +1,11 @@
# CSS # CSS
In this document we take a look at what CSS is and how it can be applied to a publication in **Chatty-pub**.
- [What is CSS](#css) - [What is CSS](#css)
- [Rules](#rules) - [Rules](#rules)
- [Css in chatty-pub](#chatty-pub) - [Css in chatty-pub](#chatty-pub)
- [Print settings](#print-settings)
- [Typing Emoji](#emoji) - [Typing Emoji](#emoji)
## What is CSS? ## What is CSS?
@ -30,7 +33,7 @@ The following code shows a very simple CSS rule that would achieve the styling d
```css ```css
h1 { h1 {
color: red; color: red;
font-size: 5em; font-size: 20px;
} }
``` ```
@ -64,8 +67,17 @@ To target the class of special you can create a selector that starts with a full
The peroid character in front of special tells the browser that we're creating a class selector. The peroid character in front of special tells the browser that we're creating a class selector.
You can apply the class of special to any element on your page that you want to have the same look as this list item. You can apply the class of special to any element on your page that you want to have the same look as this list item.
<!-- As said, in this example we're selecting a ```H1``` (Heading 1) to style, but there are other ways to select elements. In **Chatty-pub** specifically we use something called a class. A class is a propery you can add to HTML elements, and if you write a CSS selector for that class, the rules in the class will be apply to each element that ### Units
has that class. -->
In the `h1` example above, we set the following property: `font-size: 20px;`. This will set the font-size of all H1 headers to 20 pixels. But pixels are not the only units available. Some examples:
- `em` and `rem` - these relative units declare a size dependant on the font-size of the context they get used in. This can be a bit confusing if you're not used to it. Feel free to replace it with on of the values below.
- `px` - Pixels.
- `cm` and `in` - centimeters and inches. These units are mostly relevant in print context.
- `vw` and `vh` - so called viewport units, 100vw is exactly the height of the viewport (the part of the browser that shows the webpage). `vh` is the same, but for the height of the browser.
- `rgba(r,g,b,a)` strictly speaking not a unit but a function, but it sets the color and transparency of the foreground.
[More information on units](https://www.w3.org/Style/Examples/007/units.en.html).
## CSS in Chatty-pub ## CSS in Chatty-pub
@ -87,11 +99,54 @@ Because of the way Zulip handles the emoji reactions, not all emoji are availabl
You can't enter a tab character in Zulip and the indentation before the property in the rule isn't absolutely necessary. So feel free to leave it out. If you absolutely want to have the indentation, you could write the rule in your favorite editor and copy and paste it into Zulip. If you only want to style a single property you could have the whole rule on a single line like this: `🌕 { box-shadow: 0 0 20px rgba(255,0,0,0.5); }`, You can't enter a tab character in Zulip and the indentation before the property in the rule isn't absolutely necessary. So feel free to leave it out. If you absolutely want to have the indentation, you could write the rule in your favorite editor and copy and paste it into Zulip. If you only want to style a single property you could have the whole rule on a single line like this: `🌕 { box-shadow: 0 0 20px rgba(255,0,0,0.5); }`,
_Don't forget the semi-colon at the end of the property line!_. _Don't forget the semi-colon at the end of the property line!_
### Advanced CSS
**Selecting HTML elements and other style rules**
The reaction/emoji method described above allows to make quick modifications to the style and layout of your publication. But besides this **Chatty-pub** also allows you to style html elements like in regular CSS. To do this just enter your style rule. This snippet will give all HTML links a pink background color:
```css
a {
background-color: pink;
}
```
You should be able to enter all regular CSS rules this way.
**Bypassing the parser** -_Work in progress_-
It is possible to bypass the parser and add arbitrary code to the CSS on the page. This allows you to add, for example, `@key` or media queries. To do this send any message to the #rules channel and wrap the message in three backticks like this:
<code>
```
@keyframes example {
from {background-color: red;}
to {background-color: yellow;}
}
```
</code>
## Print settings
To set the paper size we can use the special selector `@page`. The following snippet set the page size to A5.
```css
@page {
size: 148mm 210mm;
}
```
Regrettably browser support for `@page` is [spotty](https://caniuse.com/css-paged-media). You will get the best results using Google Chrome.
[Pagedmedia.org](https://www.pagedmedia.org/pagedjs-sneak-peeks/) has an excellent explanation on using `@page`. The [Paged media module](https://developer.mozilla.org/en-US/docs/Web/CSS/Paged_Media) at Mozilla also.
It may be necessary to use the methods described under [Advanced CSS](#advanced-css) above to enter these rules.
## List of common and handy CSS properties ## List of common and handy CSS properties
There are hundreds of CSS properties, so I can't list them all here. Below is a small selection of some basic properties grouped by module. Most of them are self explainatory, otherwise I've added a small note. There are hundreds of CSS properties. Below is a small selection of some basic properties mostly focussed on layout and type representation, grouped by module.
### Backgrounds and borders ### Backgrounds and borders