CRAFTING UI
Frontend Design
Overblik og recap
Blive bedre til CSS
Forstå, hvordan Nesting hjælper med organisering
Blive bedre til at bruge
Øvelser, øvelser og flere øvelser for at opbygge praktisk erfaring
Forstå bedre
Blive bedre til CSS og udvide kendskabet
Forstå, hvordan hjælper med organisering
Øvelser for at opbygge praktisk erfaring
Mål: Forstå the cascade bedre
... og venner
<!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: green;
font-size: 1.1rem;
border: 1px solid blue;
}
section {
border: inherit;
}
section p {
color: red;
font-size: 1rem;
}
Properties, der nedarves:
color
font-family
font-size
font-weight
line-height
list-style
text-align
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";
}* {
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 én 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;
}Det perfekte diagnosticeringsværktøj
Et bedre udgangspunkt
Et bedre udgangspunkt
"Starter"
body {
margin: unset;
min-height: 100svh;
}img {
vertical-align: middle;
max-width: 100%;
height: auto;
}html {
font-family: system-ui;
line-height: 1.5;
color: #3b3b3b;
}* {
margin: 0;
box-sizing: border-box;
}body {
min-height: 100svh /* 100dvh */;
}
...* {
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
Mål: Forstå principperne bag
Jeres tur
0,0,0
0,0,1
Layer A
Layer B
Layer C
Layer A
Layer B
Layer C
input[type="text"] {
border: 1px solid gray;
}.my-input {
border: 4px solid blue;
}Højeste prioritet
Laveste prioritet
Layer A
Layer B
Layer C
input[type="text"] {
border: 1px solid gray;
}.my-input {
border: 4px solid blue;
}Højeste prioritet
Laveste prioritet
Layer A
Layer B
Layer C
input[type="text"] {
border: 1px solid gray;
}.my-input {
border: 4px solid blue;
}Højeste prioritet
Laveste prioritet
@layer reset {
/* ... other reset rules */
input[type="text"] {
border: 1px solid gray;
}
}
@layer components {
/* ... other component rules */
.my-input {
border: 4px solid blue;
}
}input[type="text"] {
border: 1px solid gray;
}.my-input {
border: 4px solid blue;
}Layer A
Layer B
@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;
}
}@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
@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, utils;øvelse
Oversæt selectoren (ItsLearning)
Refleksion i plenum
Mål: Blive bedre og udvide kendskabet samt vurdere kvalitet og vedligeholdelse
Mål: Blive bedre og udvide kendskabet
artcle:has(img) {}
p:not(.lede) { ... }
article > :is(.class, #id) { ... }
article > :where(.class, #id) { ... }article:has(h2) { ... }
article:has(h2, h3) { ... }
article:has(h2):has(h3) { ... }
article:not(:has(h2)) img { ... }
article:has(> :nth-child(3)) { ... }body {
display: grid;
}
body:has(main + aside) {
grid-template-columns: 1fr 300px;
}"Kom i gang"-øvelser
:not(:has(img))
i kombination med :not()
combinators
(mellemrum)
+
~
>combinators
p + figure {
...
}
figure ~ p {
...
}<div>
<p>Hello</p>
<figure></figure>
<h2>Hello</h2>
</div>
<div>
<p>Hello</p>
<h2>Hello</h2>
<figure></figure>
<p>Hello</p>
</div>combinators
p:has(+ figure) {
...
}
figure:has(~ p) {
...
}<div>
<p>Hello</p>
<figure></figure>
<h2>Hello</h2>
</div>
<div>
<p>Hello</p>
<h2>Hello</h2>
<figure></figure>
<p>Hello</p>
</div>display: contents?
p:has(img) {
display: contents;
}<article>
<img>
</article><p></p>p:has(img) {
display: contents;
}<article>
<img>
</article><p></p>p:has(img) {
display: contents;
}<article>
<img>
</article><p></p>Opfører sig nu som barn af <article>
quantity queries
ul:not(:has(> li:nth-child(5))) {
display: flex;
justify-content: center;
}Mål: Forstå, hvordan det hjælper med organisering
section {
border: 2px solid red;
}
section
color: red;
}h2 {section {
border: 2px solid red;
color: red;
}h2 {
color: red;
}section {
border: 2px solid red;
color: red;
}
}>h2 {<section>
<h2></h2>
<h3></h3>
<p></p>
<article>
<h2></h2>
</article>
</section>section {
border: 2px solid red;
color: red;
}
}>h2 {<section>
<h2></h2>
<h3></h3>
<p></p>
<article>
<h2></h2>
</article>
</section>section {
border: 2px solid red;
color: red;
}
}h2, h3 {<section>
<h2></h2>
<h3></h3>
<p></p>
<article>
<h2></h2>
</article>
</section>
:is()
:where()
:nth-child()
.
>
+
~
[data-*]
&
Symboler
h1,
h2 {
& span {
color: blue;
}
}& === :is(h1, h2)h1 {
color: red;
@media (width > 500px) {
color: blue;
}
}h1 {
@media (width > 500px) {
color: blue;
}
color: red;
}h1 {
article & {
color: red;
}
}h1 {
color: blue;
article & {
color: red;
}
}if / else
<h1>I'm blue</h1>
<div class="parent">
<h1>I'm red</h1>
</div>h1 {
color: blue;
article & {
color: red;
}
}if / else
<h1>I'm blue</h1>
<article>
<h1>I'm red</h1>
</article>h2 {
color: blue;
section :nth-last-child(2 of &) {
color: red;
}
}Please don't
a {
background: red;
&:hover {
background: blue;
}
}Co-location
Please do
.btn {
padding: 0.5rem;
&:is(:hover, :focus-visible) {
background: blue;
}
}Co-location
Please do
.container {
display: grid;
gap: 1rem;
@media (width > 600px) {
grid-template-columns: repeat(3, 1fr);
}
}Co-location
Please do
Omskriv til nesting
Al logik skal være i article
article {
/* nesting logik */
}section:nth-child(...) {
article {
}
}✅
🚫
Al logik skal være i .article