id > class > element >>> The most specific is always the one taken into account
The last CSS sheet style link will have priority against the one placed above. Same for JS. (So for example always put your own CSS after jQuery or Boostrap)
You can import a CSS file within another CSS file (even from an external source):
So a good practice is to link your index.html to one home.css or index.css file, and put all the other CSS sheets inside this same file
The format of a CSS gradient filter:
By default, blocks will stack on top of each other. Then the position propriety can take those values:
So a common patern is:
Offset properties: left right top bottom. Can be set in px, em, or %. Doesn't work on static elements.
Z-index: greater z-index will be in front of lower z-index. Doesn't work on static elements.
Display propriety dictate if an element can share horizontal space with others or not
Example:
float: left or float: right will move an element as far as left/right as possible. It must have a specified width (otherwise it will have the full width of its containing element and moving it right or left will not have any visible results).
A floating element will be removed from the flow. Which means for example that if it is inside a div, this div will lose its height.
When an element is floating, if it doesn't take full width of the page, following elements will come next to it. To avoid that you can use the propriety clear on the following elements. It will prevent them to go next to the floating element.
Border style values : Moz doc
If an element with a fixed width has the property: margin: 0 auto;, it will center it in its containing elements.
Horizontal margins (let and right) between two elements are added together to define the space between those elements.
On the contrary, vertical margin collapse. It means that they are packed together and thus the larger of the two vertical margins will set the distance between two elements:
>>> There will be 40px of horizontal space between those two elements.
>>> But There will be 30px of vertical space between those two elements (and not 50px)
The overflow property allows you to control what happens to a content if it spills or overflows outside its box :
The overflow is set on a parent element to affect its child elements.
You can also define overflow-x or overflow-y to only affect the horizontal or vertical part of the element that overflows the box
All web browsers have default stylesheet values (known as "user agent"). Often set a default value for padding and margin for example. So it is useful to reset those values with the * propriety:
(When you set a value to 0 in CSS you don't need any unit measurement).
Other proprieties may be useful to reset: Code Ac
By setting the default model of all HTML elements to border-box, with the box-sizing propriety like that:
You define a new box model called "border-box" that have the following proprieties:
Overall it makes that the width and height of your element is not affected by the padding and border.
RGB Model:
In RGB system, if you put the same value for the 3 colors, you are on the grey scale. At 0 you are totally black and at 255 you are totally white. And in between you have greyscales:
HSL Model:
HSL = hue, saturation, lightness. Synthax: color: hsl(120, 60%, 70%) :
Useful if you just want to change the lightness or saturation of a color (more complex in RGB). Also usfull if you whant to have a set of colors that work well together: same saturation and lightness.
As for RGB you also have the HSLA model with transparency.
In CSS you have the system of fallback fonts:
sThis says "use Garamond, if not available, use Times, if not available, any serif font pre-installed on the user device".
Font types are:
Font weight values range from 100 to 900 and can only be multiples of 100 (100, 200, 500...)
Font proprieties:
Font-face:
You can use font-face to load any font you want into the browser of your user. You can use it with your own font in your own server or with an external source. You need to specify :
To work, a CSS grid needs a grid container and grid items.
Grid containers: must have the propriety: display: grid;
Inside containers you define columns:
Inside containers you also define rows:
You can also use one propriety for both rows and columns: colums: grid-template
(Before the / are rows, after are columns)
Fractions: the fr unit define the size of columns and rows as a fraction of grid length.
Ex: grid-template: 2fr 1fr 1fr / 1fr 3fr 1fr >>> first row will be 2/4 of the grid, second row 1/4, third row 1/4. First column will be 1/5, second 3/5, third 1/5.
(If you use fr combined with other units ; the fr will represent a fraction of the available space.)
Repeat: You can use the repeat fonction like that: grid-template-columns: repeat(3, 100px) >>> is the same as writting : grid-template-columns: 100px 100px 100px
Minmax: grid-template-columns: 100px minmax(100px, 500px) 100px >>> the 2nd column will vary between 100px and 500px depending on the size of the overall grid. (For minmax to work your grid can't have a fixed size).
Grid Gap:
Grid items:
grid-row-start and grid-row-end make a single grid items take up multiple rows. Same for grid-column-start and grid-column-end.
>>> The element .item will starts at row 1 and stops at row 3 (so it will take the space of 2 rows). Same for columns.
You can also use it like that: grid-row: 1 / 3 and grid-column: 1 / 3 >>> Will start at 1 and stop at 3.
You can also use the span kw: grid-column: 4 / span 2 >>> means item will starts at column 4 and take 2 spaces. (So stops at 6).
So all the following statements are exactly the same:
Grid area: grid-area: w / x / y / z allows you to define all your rows and columns at the same time:
So grid-area: 2 / 3 / 4 / span 5; >>> means this item will start at row 2 and end at row 4. It will start at column 3 and take 5 column space.
Grid template areas: grid-template-areas property allows you to name sections of your webpage to use it as values of a grid.
Example:With this code you build the following grid:
(Don't forget to declare each elements with the grid-area propriety)
Justify Items: allows you to align items horizontally inside the grid area.
Align Items: allows you to align items vertically inside the grid area.
Both can take following values:
Justify Content: allows to position an entire grid horizontally within its parent element.
Align Content: allows to position an entire grid vertically within its parent element.
Both can take following values:
Justify Self and Align Self:
Implicit Grid
If you can't define in advance how many rows/columns you will have on your grid, the implicit grid takes over. Default rules of the implicit grid are:
You can modify those default behaviors with the following proprieties:
With grid-auto-flow you can also specify if you want new elements to be added to rows or columns. It can takes following values: