Frontend Design
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
Blive bedre til CSS og udvide kendskabet
Forstå, hvordan hjælper med organisering
Blive bedre til at bruge
Øvelser, øvelser og flere øvelser for at opbygge praktisk erfaring
Oversæt selectoren (Fronter)
Vi kigger på det i plenum
Mål: Blive bedre og udvide kendskabet
li:nth-last-child(odd):first-child
Vælg det første liste-element i rækken, men kun hvis det samtidigt er ulige, hvis man tæller fra slutningen af listen.
:nth-child(2 of .featured)
Vælg det andet element, men kun hvis det er en af de elementer, der har 'featured'-klassen.
Mål: Blive bedre og udvide kendskabet
artcle:has(> img) {}
p:not(article > *) { ... }
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(> :last-child:nth-child(3)) { ... }
body {
display: grid;
}
body:has(main + aside) {
grid-template-columns: 1fr 300px;
}
50ch
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>
ul:not(:has(> li:nth-child(5))) {
display: flex;
justify-content: center;
}
:root:has(dialog[open]) {
overflow: hidden;
}
Loading...
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;
}
}
:is( , h3)
h2 {
<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;
& {
color: blue;
}
}
h1 {
color: red;
@media (width > 500px) {
color: blue;
}
}
h1 {
@media (width > 500px) {
color: blue;
}
color: red;
}
h1 {
@media (width > 500px) {
color: blue;
}
color: red;
}
h1 {
color: red; /* hoisted */
@media (width > 500px) {
color: blue;
}
}
1
2
h1 {
& {
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>
h1 {
color: blue;
section article & span {
color: red;
}
}
a {
background: red;
&:hover {
background: blue;
}
}
Co-location
a {
background: red;
&.btn {
padding: .5rem;
&:hover {
background: blue;
}
}
}
Co-location
a {
background: red;
&.btn {
padding: .5rem;
&:is(:hover, :focus-visible) {
background: blue;
}
}
}
Co-location
Øvelse
Omskriv til nesting
Øvelse
Al logik skal være i .article {}
Mål: Blive bedre og få mere erfaring
Grid-øvelser: https://exercssises.vinther.codes/grid/
Flex-øvelser: https://exercssises.vinther.codes/flex/
Hvad skal jeg vælge?
Hvordan gør jeg det nemmest for mig selv?
Erfaring
Flex Pattern
.task {
flex: 1;
}
.container {
display: grid;
grid-template-columns: 1fr minmax(0, 1200px) 1fr;
column-gap: 1rem;
> * {
grid-column: 2;
}
.full-bleed {
grid-column: 1 / -1;
}
}
Grid Pattern
.container {
display: grid;
grid-template-columns: 1fr minmax(0, 1200px) 1fr;
column-gap: 1rem;
> * {
grid-column: 2;
}
.full-bleed {
grid-column: 1 / -1;
}
}
Grid Pattern
Grid Pattern
.container {
display: grid;
grid-template-columns:
[full-start] 1fr [content] minmax(0, 1200px) 1fr [full-end];
column-gap: 1rem;
> * {
grid-column: content;
}
.full-bleed {
grid-column: full;
}
}
.grid-pile {
display: grid;
}
.grid-pile > * {
grid-area: 1 / 1;
}
Grid Pattern
øvelse
Lav øvelsen, der ligger på git-branch'en "citd-1" på GitHub
.container {
display: grid;
grid-template-rows: 1fr 1fr 1fr 1fr;
gap: 20px;
}
.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 20px;
}
.container
.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 20px;
}
.container
.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 20px;
}
.container
* works as documented but is counter-intuitive
Kan du løse denne?