Garrit Schaap
Lecturer at the School of Engineering - Jönköping University.
2022
Specificity is the means by which browsers decide which CSS property values are the most relevant to an element and, therefore, will be applied.
Find more infos on MDN
Normally, you can only use fonts that are installed on the users machine. That is why we are using this prioritized lists.
But there is a way to embed fonts from TypeKit, Google Fonts or your own server into your website.
Find more infos on CSS-Tricks
Inside your CSS:
@font-face {
font-family: 'Open Sans';
font-style: normal;
src: url(opensans.woff) format('woff');
}
Inside your CSS:
@import url('https://fonts.googleapis.com/css2?family=Open+Sans&display=swap');
body {
font-family: 'Open Sans', sans-serif;
}
body {
font-family: 'Open Sans', sans-serif;
}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
The more fonts and font-styles you add, the longer your website needs to load
Find more infos on CSS-Tricks
Float comes from classic print layouts and is used in web design as well
Find more infos on CSS-Tricks
Or how to center things vertically and horizontally
Find more infos on CSS-Tricks
Flexbox layout is most appropriate to the components of an application, and small-scale layouts, while the Grid layout is intended for larger scale layouts.
main-axis
cross-axis
.container {
display: flex; /* or inline-flex */
}
.container {
flex-direction: row; /* row-reverse, column, column-reverse */
}
row
row-reverse
column
column-reverse
.container {
flex-wrap: nowrap; /* wrap, wrap-reverse */
}
wrap
.container {
flex-flow: column wrap;
}
.container {
justify-content: flex-start /* flex-end, center, space-between, space-around, space-evenly, start, end, left, right ... + safe, unsafe */
}
flex-start
flex-end
center
space-between
.container {
align-content: flex-start; /* flex-end, center, space-between, space-around, space-evenly, stretch, start, end, baseline, first baseline, last baseline + ... safe, unsafe */
}
space-between
flex-start
Only takes effect if flex-wrap is set to wrap or wrap-reverse!
.container {
gap: 10px;
gap: 10px 20px; /* row-gap column gap */
row-gap: 10px;
column-gap: 20px;
}
gap: 40px
.item {
order: 5; /* default is 0 */
}
-1
1
1
3
7
.item {
flex-grow: 4; /* default 0 */
}
1
2
1
1
1
1
.item {
flex-shrink: 3; /* default 1 */
}
.item {
flex-basis: 100px; /* default auto */
}
.item {
flex: 2 1 auto; /* flex-grow flex-shrink? flex-basis? */
}
This is the shorthand syntax for flex-grow, flex-shrink and flex-basis
.item {
align-self: auto; /* flex-start, flex-end, center, baseline, stretch */
}
flex-start
flex-end
Grid layout is intended for larger scale layouts
Find more infos on CSS-Tricks
<div class="container">
<div class="item item-1"> </div>
<div class="item item-2">
<p class="sub-item">Some text</p>
</div>
<div class="item item-3"> </div>
</div>
1
2
3
4
1
2
3
1
2
3
4
1
2
3
Grid line
1
2
3
4
1
2
3
Grid cell
1
2
3
4
1
2
3
Grid track
1
2
3
4
1
2
3
Grid area
.container {
display: grid; /* inline-grid */
}
.container {
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
}
.container {
grid-template-columns: 1fr 4fr 1fr;
grid-template-rows: 80px 1fr 80px;
grid-template-areas:
"header header header"
". content ."
"footer footer footer";
}
.container {
grid-template-columns: 1fr 4fr 1fr;
grid-template-rows: 80px 1fr 80px;
grid-template-areas:
"header header header"
". content ."
"footer footer footer";
}
header
content
footer
.
.
.container {
row-gap: 20px;
column-gap: 16px;
/* ...or... */
gap: 20px 16px;
}
row-gap
column-gap
.container {
justify-items: start; /* end, center, stretch */
}
start
stretch
.container {
align-items: start; /* end, center, stretch */
}
start
center
.container {
place-items: center; /* align-items / justify-items */
}
.container {
justify-content: start; /* end, center, stretch, space-around, space-between, space-evenly */
}
space-between
start
.container {
align-content: start; /* end, center, stretch, space-around, space-between, space-evenly */
}
center
space-between
.container {
place-content: center; /* align-content / justify-content */
}
.container {
grid-auto-columns: 100px;
grid-auto-rows: 100px;
}
.container {
grid-auto-flow: row; /* column, row dense, column dense */
}
.container {
grid: 100px 300px / 3fr 1fr;
}
.container {
grid-template-rows: 100px 300px;
grid-template-columns: 3fr 1fr;
}
.item {
grid-column-start: 1; /* name, span <number>, span <name>, auto */
grid-column-end: 2; /* name, span <number>, span <name>, auto */
grid-row-start: 1; /* name, span <number>, span <name>, auto */
grid-row-end: 3; /* name, span <number>, span <name>, auto */
}
1
2
3
4
1
2
3
.item {
grid-column: 2 / 4;
grid-row: 2 / 3;
}
1
2
3
4
1
2
3
.item {
grid-area: header; /* <row-start> / <column-start> / <row-end> / <column-end> */
}
header
content
footer
.
.
.item {
justify-self: start; /* end, center, stretch */
}
end
start
center
stretch
.item {
align-self: start; /* end, center, stretch */
}
end
start
center
stretch
.item {
place-self: center; /* <align-self> / <justify-self> */
}
Find more infos on CSS-Tricks
https://cssgrid-generator.netlify.app
This can be a starting point, but please try it yourself first.
...and custom CSS properties
Find more infos on CSS-Tricks
.element {
background-image: url(image/background.jpg);
}
.element {
background-image: url(image/background.jpg);
}
property
function name
parameter
.element {
width: calc(100vw - 80px);
}
html {
--color: orange;
}
h1 {
color: var(--color);
}
More infos on CSS-Tricks
.element {
color: rgb(255, 0, 0);
color: rgba(255, 0, 0, 0.5);
color: rgb(255 0 0 / 0.5);
}
.container {
background: hsl(100, 100%, 50%);
background: hsla(100, 100%, 50%, 0.5);
background: hsl(100 100% 50% / 0.5);
}
There is also radial-gradient() and repeating-radial-gradient()
html {
background: linear-gradient(#ff00ff, #00ff00);
}
.container {
background: repeating-linear-gradient(45deg, #ff00ff, #00ff00 15%, #ff0000 20%);
}
More infos on MDN
.element {
filter: blur(50%);
}
.element {
filter: brightness(150%);
}
.element {
filter: drop-shadow(0 2em 4px #000000);
/* (offset-x offset-y blur-radius color) */
}
.element {
transform: scale(0.5);
}
.element {
transform: translate(10px 50px);
}
.cube {
transform: perspective(50em) rotateY(50deg);
}
.cube {
transform: perspective(50em) rotateY(50deg);
}
.element {
transform: skew(25deg, 15deg);
}
.element {
width: clamp(320px, 80%, 900px);
}
.minimum-of-these {
width: max(500px, 50%);
}
.maximum-of-these {
width: min(320px, 90%);
}
They are all used on the clip-path property for masking images.
You can find more infos at MDN
By Garrit Schaap