Reviewing CSS
CSS is for presentation
CSS is for presentation
Ideally, we don’t want to include style information within the HTML document itself. So we put all our style information in separate CSS files and use
<link>elements to link these files into our documents.
| |
This is very flexible. A common stylesheet can be used across multiple documents. We can also have multiple stylesheets attached to a single document if we want.
A CSS ruleset consists of a [group of] selector[s] and a declaration block (between curly brackets) containing one or more declarations. Where Each declaration consists of a property name, a colon and a value, followed by a semi-colon.
| |
Typically, each declaration is given it’s own line. One-line formatting is also common but should only be used when there is only one declaration.
| |
Spaces and newline characters are ignored. However, consistent formatting is expected.
CSS declarations are a way to set CSS properties of elements to given values. The selector determines which elements are targetted by the ruleset.
| |
In the above examples the selectors are body, p and a respectively.
CSS declarations can have multiple values, typically separated by spaces or commas.
| |
Some properties are shorthand properties provided for convenience.
| |
The
borderproperty is shorthand for settingborder-width,border-styleandborder-colorsimultaneously.
In HTML, class attributes (
class="student") can be used to identify similar elements. Class selectors (the dot, e.g..student) can be used for selecting elements with a specific class attribute. Similarly, id attributes (id="students") can be selected with a hash (e.g.#students).
| |
| |
Selectors allow us to specify which elements will be affected by a ruleset. There are several patterns (known as combinators) we can use for selectors which allow us to target specific elements.
Separating elements with spaces (e.g.
p a) is the descendent combinator.
| |
Using a greater than symbol (e.g.
p > a) is the child combinator
| |
Using a plus symbol (e.g.
h1 + p) is the next sibling combinator
| |
Read more about selectors and combinators.
By default, content is arranged in a page according to the flow layout.
| |
Block elements take up the full width of their container. Inline elements flow like text. Everything flows, wraps and adjusts according to the size of the viewport.
flex-direction controls which dimension becomes the main axis.
justify-content controls how elements are distributed on the main axis.
align-items controls how elements are placed on the cross-axis.
gap sets the minimum space between elements.
For more control also see:
flex-grow, flex-shrink, flex-basis and flex-wrap .
grid-template-columns determines the number and type of columns.
| |
| |
| |
| |
Setting the
displayproperty of an element will change the way the element behaves.We have seen the difference between
blockandinline. These can be controlled by setting thedisplayproperty.
These are controlling the outer display type which controls how the element participates in the flow layout.
We can provide other values for the
displayproperty to control the formatting context for child elements.These change the default flow layout to either
flexorgridlayout.
These are controlling the outer display type which controls how the element participates in the flow layout.
If you have any questions, now is a good time to ask.
Thanks for listening