Reset, inheritance, specificity, layers
* {
margin: 0;
box-sizing: border-box;
}
img {
display: block;
max-width: 100%;
height: auto;
}
html {
display: block;
}
head {
display: none;
}
body {
display: block;
margin: 8px;
}
h1 {
display: block;
font-size: 2em;
margin-block-start: 0.67em;
margin-block-end: 0.67em;
font-weight: bold;
}
a:-webkit-any-link {
color: -webkit-link;
cursor: pointer;
text-decoration: underline;
}
En masse regler er defineret, inden du selv har skrevet en linje CSS
Browser
.example {
display: flex;
}
.example > .child {
}
.example {
display: flex;
align-items: stretch;
justify-content: normal;
align-content: normal;
align-items: normal;
flex-direction: row;
flex-wrap: nowrap;
}
.example > .child {
flex-grow: 0;
flex-shrink: 1;
flex-basis: auto;
}
* {
border-style: solid;
border-width: 0;
}
* {
border-style: solid;
border-width: 0;
}
:not(progress, meter) {
border-style: solid;
border-width: 0;
}
Et bedre udgangspunkt
h1,
h2,
h3 {
text-wrap: balance;
}
p {
text-wrap: pretty;
}
body {
min-height: 100svh /* 100dvh */;
}
h1,
h2,
h3 {
text-wrap: balance;
}
p {
text-wrap: pretty;
}
* {
margin: 0;
box-sizing: border-box;
}
img {
display: block;
max-width: 100%;
height: auto;
}
:not(progress, meter) {
border-style: solid;
border-width: 0;
}
body {
min-height: 100svh /* 100dvh */;
}
h1,
h2,
h3 {
text-wrap: balance;
}
p {
text-wrap: pretty;
}
* {
margin: 0;
box-sizing: border-box;
}
img {
display: block;
max-width: 100%;
height: auto;
}
:not(progress, meter) {
border-style: solid;
border-width: 0;
}
Temaets reset
:not(.special) a {
color: red;
}
<ul>
<li>
<a>Link</a>
</li>
<li class="special">
<a>Link</a>
</li>
<li>
<a>Link</a>
</li>
</ul>
p {
color: green;
}
#context {
color: red;
}
<div id="context">
<p>Some text</p>
</div>
<!DOCTYPE html>
<html lang="da">
<head>...</head>
<body>
<p>Brødtekst <span>her</span>...</p>
</body>
</html>
<p>Brødtekst <span>her</span>...</p>
Brødtekst her...
<span>
body {
color: red;
}
Brødtekst her...
<!DOCTYPE html>
<html lang="da">
<head>...</head>
<body>
<p>Brødtekst <span>her</span>...</p>
</body>
</html>
<p>Brødtekst <span>her</span>...</p>
Brødtekst her...
<!DOCTYPE html>
<html lang="da">
<head>...</head>
<body>
<p>Brødtekst <span>her</span>...</p>
</body>
</html>
<p>Brødtekst <span>her</span>...</p>
body {
color: red;
}
p {
color: blue;
}
Brødtekst her...
<!DOCTYPE html>
<html lang="da">
<head>...</head>
<body>
<p>Brødtekst <span>her</span>...</p>
</body>
</html>
<p>Brødtekst <span>her</span>...</p>
p {
color: blue;
}
span {
color: #000;
}
<!DOCTYPE html>
<html lang="da">
<head>...</head>
<body>
<h1>Heading 1</h1>
<main>
<h2>Heading 2</h2>
<p>Lorem ipsum dolor sit.</p>
<section>
<h3>Hello</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</section>
</main>
</body>
</html>
body {
color: red;
}
<!DOCTYPE html>
<html lang="da">
<head>...</head>
<body>
<h1>Heading 1</h1>
<main>
<h2>Heading 2</h2>
<p>Lorem ipsum dolor sit.</p>
<section>
<h3>Hello</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</section>
</main>
</body>
</html>
main {
color: red;
}
<!DOCTYPE html>
<html lang="da">
<head>...</head>
<body>
<h1>Heading 1</h1>
<main>
<h2>Heading 2</h2>
<p>Lorem ipsum dolor sit.</p>
<section>
<h3>Hello</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</section>
</main>
</body>
</html>
section {
color: red;
}
<!DOCTYPE html>
<html lang="da">
<head>...</head>
<body>
<h1>Heading 1</h1>
<main>
<h2>Heading 2</h2>
<p>Lorem ipsum dolor sit.</p>
<section>
<h3>Hello</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</section>
</main>
</body>
</html>
section p {
color: red;
}
<!DOCTYPE html>
<html lang="da">
<head>...</head>
<body>
<h1>Heading 1</h1>
<main>
<h2>Heading 2</h2>
<p>Lorem ipsum dolor sit.</p>
<section>
<h3>Hello</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</section>
</main>
</body>
</html>
main {
font-size: 1.1rem;
}
section p {
color: red;
}
<!DOCTYPE html>
<html lang="da">
<head>...</head>
<body>
<h1>Heading 1</h1>
<main>
<h2>Heading 2</h2>
<p>Lorem ipsum dolor sit.</p>
<section>
<h3>Hello</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</section>
</main>
</body>
</html>
main {
font-size: 1.1rem;
}
section p {
color: red;
font-size: 1rem;
}
Properties, der nedarves:
color
font-family
font-size
font-weight
line-height
list-style
text-align
m.m.
html {
color: gray;
line-height: 1.5;
font-family: system-ui, sans-serif;
}
h1,
h2,
h3 {
color: #000;
line-height: 1.1;
font-family: "My Display Font";
}
Mål: Forstå principperne bag
Mål: Forstå principperne bag
Jeres tur
p:not(#id) {
color: green;
}
p.class {
color: red;
}
<p class="class">text</p>
<p id="id">last text</p>
p.test a {
color: green;
}
a:hover {
color: deeppink;
}
<p class="test">
<a href="#0">Hvilken farve?</p>
</p>
0,0,0
0,0,1
@layer reset {
/* ... other reset rules */
input[type="text"] {
border: 1px solid gray;
}
}
@layer components {
/* ... other component rules */
.my-input {
border: 4px solid blue;
}
}
@layer reset, components, utilities;
@layer reset {
/* ... other reset rules */
input[type="text"] {
border: 1px solid gray;
}
}
@layer components {
/* ... other component rules */
.my-input {
border: 4px solid blue;
}
}
configure up front
@layer reset, components, utilities;
@layer components {
/* ... other component rules */
.my-input {
border: 4px solid blue;
}
}
@layer reset {
/* ... other reset rules */
input[type="text"] {
border: 1px solid gray;
}
}
1
2
3
configure up front
@layer reset, components, states;
@layer components {
/* Buttons, inputs etc. */
}
@layer states {
/* Make sure stats override, no matter specificity count */
:disabled {
background-color: #ddd;
color: #999;
}
:focus-visible {
outline: 2px solid var(--focus-color, currentColor);
outline-offset: 2px;
}
}
@layer a, b;
@layer a {
header#my-header nav#my-nav ul li.link-item:hover {
color: red;
}
}
@layer b {
.link-item {
color: blue;
}
}
@layer reset, global, components, utilities;
@layer reset, global, components, utilities;
Hvert projekt
Projektspecifikt?
Projektspecifikt!
One-offs, hvert projekt?
@layer reset, global, components, utilities;
@layer reset {
ul[class] {
margin: 0;
padding: 0;
list-style: none;
text-align: start;
}
}
@layer utilities {
.flow {
> * + * {
margin-top: 1em;
}
}
}
eksempel
øvelse
ul[class] {
margin: 0;
padding: 0;
list-style: none;
}
øvelse
.flow {
> * + * {
margin-top: 1rlh;
}
}
øvelse
ul[class] {
margin: 0;
padding: 0;
list-style: none;
}
.flow {
> * + * {
margin-top: 1rlh;
}
}
0,1,1
0,1,0
øvelse
@layer reset, global, components, utilities;
@layer reset, global, components, utilities;
@import "./reset.css" layer(reset);
@layer global {
...
}
Astro
Astro
---
---
<article class="card">
...
</article>
<style>
@layer components.card {
article {
/* component specific styles */
}
}
</style>