Skip to content

Commit 30f0975

Browse files
author
Peter Hozak
committed
add remaining examples
1 parent 72c079e commit 30f0975

File tree

9 files changed

+146
-9
lines changed

9 files changed

+146
-9
lines changed

03-css-debugging/README.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ cd src/examples/
4242
* if they need to overlap in arbitrary ways, best to go `absolute`
4343
* or [`grid`](https://css-tricks.com/snippets/css/complete-guide-grid/) (order in HTML according to Z order, manual row+column for position)
4444
* 03 Selector specificity
45-
* TODO
46-
* 04 Responsive
47-
* TODO
45+
* CSS [Cascade](https://developer.mozilla.org/en-US/docs/Web/CSS/Cascade) and [Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity)
46+
* Simplified model - do a sum of "values" for each part of the selector:
47+
* 1 for `div` or `::before`
48+
* 10 for `.class` or `:hover`
49+
* 100 for `#id`
50+
* 999 for inline
51+
* 1000 for `!important` in the rule
52+
* 04 Responsive design
53+
* Always test, open multiple windows or connect devices
54+
* `flex-wrap`, `grid-template-columns`, `<Col md={12} />`, `min-width`, ... not just @media
4855
* 05 Transitions
49-
* TODO
56+
* `transition` property applied from the "after" / "new" selector
57+
* Q&A

03-css-debugging/src/App.scss

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
.App {
22
display: flex;
33
flex-direction: column;
4-
flex-wrap: wrap;
54
align-items: center;
65
height: 100vh;
7-
background: #aaa;
6+
background: #aaafae;
7+
font-size: 32px;
88
}
99

1010
.App__header {
1111
margin: 10px;
12+
display: flex;
13+
flex-wrap: wrap;
14+
justify-content: center;
1215

1316
a {
1417
color: #557;
1518
text-decoration: none;
16-
padding: 0 5px;
19+
padding: 0 10px;
20+
transition: 0.2s;
1721
}
1822
a.active {
1923
color: black;
@@ -28,7 +32,7 @@
2832
display: flex;
2933
flex: 1;
3034

31-
*:not(.Vertical) {
35+
& > *:not(.Vertical) {
3236
margin: auto;
3337
}
3438
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
import {Button} from './../lib'
3+
4+
const Example = () => (
5+
<div className="Selector">
6+
Example 03: "cascade" style sheets
7+
<Button>Default</Button>
8+
<Button className="Selector__buttonWannaBe">Why not changed</Button>
9+
<Button className="Selector__buttonModified">But fine here</Button>
10+
</div>
11+
)
12+
13+
export default {
14+
id: '03',
15+
title: 'Selector specificity',
16+
component: Example,
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react'
2+
3+
const boxes = Array.from(Array(50)).map((_, i) => <div>{i}</div>)
4+
const Example = () => (
5+
<div className="Responsive">
6+
{boxes}
7+
</div>
8+
)
9+
10+
export default {
11+
id: '04',
12+
title: 'Responsive design',
13+
component: Example,
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
3+
const Example = () => (
4+
<div className="Transitions">
5+
Example 05: Transition defined on "after" class
6+
</div>
7+
)
8+
9+
export default {
10+
id: '05',
11+
title: 'Transitions',
12+
component: Example,
13+
}

03-css-debugging/src/examples/examples.scss

+56-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
.first {
33
color: skyblue;
44
}
5+
56
.second {
67
color: navy;
78
}
8-
&__niceName {
9+
10+
&__niceName { // <-- won't be found by fulltext search of whole class name
911
color: maroon;
1012
}
1113
}
@@ -24,6 +26,7 @@
2426
.Z__shouldBeOnTop {
2527
z-index: 9999;
2628
}
29+
2730
.Z__evilStackingContext {
2831
position: relative;
2932
display: inline-block;
@@ -40,6 +43,58 @@
4043
}
4144

4245

46+
47+
48+
.Selector {
49+
display: flex;
50+
flex-direction: column;
51+
align-items: center;
52+
53+
&__buttonWannaBe { // <-- "value" 10
54+
background: darkolivegreen;
55+
}
56+
57+
.Selector__buttonModified { // <-- "value" 20
58+
background: darkolivegreen;
59+
}
60+
}
61+
62+
63+
64+
65+
.Responsive {
66+
width: 1200px;
67+
@media (max-width: 1200px) {
68+
width: 100%; // <-- % of what?
69+
}
70+
display: grid;
71+
grid-template-columns: repeat(auto-fit, 70px);
72+
73+
div {
74+
border: 1px solid gray;
75+
margin: 5px;
76+
text-align: center;
77+
}
78+
}
79+
80+
81+
82+
83+
.Transitions {
84+
cursor: default;
85+
color: darkolivegreen;
86+
transition: 1ms;
87+
88+
&:hover {
89+
color: green;
90+
font-weight: bold;
91+
transition: 1s;
92+
}
93+
}
94+
95+
96+
97+
4398
#ddfdsfas, div[dsfas*=fsafdsa], .first.second, .dfasfsafasdfc {
4499
// overwriting Intro styles "by accident"
45100
color: red;

03-css-debugging/src/examples/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import './examples.scss'
33
import ex00 from './00-intro'
44
import ex01 from './01-vertical-alignment'
55
import ex02 from './02-z-index'
6+
import ex03 from './03-selector-specificity'
7+
import ex04 from './04-responsive-design'
8+
import ex05 from './05-transitions'
69

710
export default [
811
ex00,
912
ex01,
1013
ex02,
14+
ex03,
15+
ex04,
16+
ex05,
1117
]

03-css-debugging/src/lib/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import React from 'react'
2+
import './lib.scss'
3+
4+
export const Button = ({className = '', children}) => <button className={`lib-button ${className}`}>{children}</button>

03-css-debugging/src/lib/lib.scss

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.lib {
2+
$bg: #998;
3+
&-button {
4+
border-radius: 5px;
5+
border: 1px solid darken($bg, 20);
6+
background: $bg;
7+
font-size: inherit;
8+
padding: 3px 10px;
9+
margin: 3px;
10+
cursor: pointer;
11+
}
12+
&-button:hover {
13+
background: darken($bg, 10);
14+
border-color: darken($bg, 100);
15+
}
16+
}

0 commit comments

Comments
 (0)