You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: P07-Style-the-List/content.md
+41-43
Original file line number
Diff line number
Diff line change
@@ -5,27 +5,27 @@ slug: styling-the-list
5
5
6
6
## The list could use some styles
7
7
8
-
The POPOSList component displays a list of POPOSSpace components. The list is only responsible for arranging the spaces. To get things to look great you'll need to style both and get those styles to work together.
8
+
The POPOSList component displays a list of POPOSSpace components. The list is only responsible for arranging the spaces. To get things to look great you'll need to style both and get those styles to work together.
9
9
10
-
This step will only cover styling the list. There may be a few issues with the way the spaces display which will be covered in another section.
10
+
This step will only cover styling the list. There may be a few issues with the way the spaces display which will be covered in another section.
11
11
12
-
Create a CSS file.
12
+
Create a CSS file.
13
13
14
-
> [info]
15
-
>
16
-
> If you haven't already create a new file: `POPOSList.css` it should be in the same folder as the `POPOSList.js` file.
17
-
>
14
+
> [action]
15
+
>
16
+
> If you haven't already create a new file: `POPOSList.css` it should be in the same folder as the `POPOSList.js` file.
17
+
>
18
18
19
-
Now import the CSS.
19
+
Now import the CSS.
20
20
21
-
> [info]
22
-
>
21
+
> [action]
22
+
>
23
23
> Next import the the new CSS file into the `POPOSList.js` add the following at the top.
24
-
>
24
+
>
25
25
> `import './POPOSList.css'`
26
26
>
27
-
> Now, in the `POPOSList` component add a class name:
28
-
>
27
+
> Now, in the `POPOSList` component add a class name:
28
+
>
29
29
```JS
30
30
functionPOPOSList() {
31
31
...
@@ -38,12 +38,12 @@ function POPOSList() {
38
38
```
39
39
>
40
40
41
-
Arranging the elements in a grid would be a good idea. Luckily CSS provides a `display: grid` property. This is similar to `display: flex`. Where flex is a one dimmensional arrangement grid is two dimmendsional. With flex everything would be arranged in a row or a column, with grid things are arranged in both rows and columns.
41
+
Arranging the elements in a grid would be a good idea. Luckily CSS provides a `display: grid` property. This is similar to `display: flex`. Where flex is a one dimmensional arrangement grid is two dimmendsional. With flex everything would be arranged in a row or a column, with grid things are arranged in both rows and columns.
42
42
43
-
> [info]
43
+
> [action]
44
44
>
45
45
> Add the following to `POPOSList.css`
46
-
>
46
+
>
47
47
```CSS
48
48
.POPOSList {
49
49
display: grid;
@@ -52,18 +52,18 @@ Arranging the elements in a grid would be a good idea. Luckily CSS provides a `d
52
52
```
53
53
>
54
54
55
-
The code above declare the parent element as display grid and defines three equal sized columns. The `1fr` is 1 fraction. the `fr` unit that is a fraction of the availble space. So `1fr 1fr 1fr` could considered the same as `33.333% 33.333% 33.333%` but it reads better and is more accurate.
55
+
The code above declare the parent element as display grid and defines three equal sized columns. The `1fr` is 1 fraction. the `fr` unit that is a fraction of the availble space. So `1fr 1fr 1fr` could considered the same as `33.333% 33.333% 33.333%` but it reads better and is more accurate.
56
56
57
-
Test this out and resize the page. There are a couple things missing.
57
+
Test this out and resize the page. There are a couple things missing.
58
58
59
59
- The grid columns and rows need some space between them
60
60
- When the page is really wide the columns are too far apart
61
61
- When the page is too narrow the columns are too close together
62
62
63
-
> [info]
64
-
>
63
+
> [action]
64
+
>
65
65
> Add the following to the `.POPSList` rule in `POPOSList.css`
66
-
>
66
+
>
67
67
```CSS
68
68
.POPOSList {
69
69
display: grid;
@@ -72,22 +72,22 @@ Test this out and resize the page. There are a couple things missing.
72
72
max-width: 1200px;
73
73
margin: auto;
74
74
padding: 2em;
75
-
}
76
-
>
75
+
}
76
+
```
77
77
78
78
-`grid-gap: 2em` adds a 2em space between rows and columns in the grid
79
79
-`max-width: 1200px` sets a maximum width for the element
80
-
- `margin: auto` makes the margins equal on the left and right this has the effect of centering the grid container on the page.
81
-
- `padding: 2em` adds some space on the left and right so the pictures don't hit the edges of the page when the window is narrow.
80
+
-`margin: auto` makes the margins equal on the left and right this has the effect of centering the grid container on the page.
81
+
-`padding: 2em` adds some space on the left and right so the pictures don't hit the edges of the page when the window is narrow.
82
82
83
-
This looks better but there are some problems when the page is narrow. Add some media queries to take care of these.
83
+
This looks better but there are some problems when the page is narrow. Add some media queries to take care of these.
84
84
85
-
A media query is a rule that is only applied some times or under certain circumstances. You'll use media queries here to make adjustments for smaller screens, like tablets, and mobile devices.
85
+
A media query is a rule that is only applied some times or under certain circumstances. You'll use media queries here to make adjustments for smaller screens, like tablets, and mobile devices.
86
86
87
-
> [info]
88
-
>
87
+
> [action]
88
+
>
89
89
> Add the following to `POPOSList.css`
90
-
>
90
+
>
91
91
```CSS
92
92
/* Smaller screens and tablets */
93
93
@mediaonlyscreenand (max-width: 960px) {
@@ -98,32 +98,30 @@ A media query is a rule that is only applied some times or under certain circums
98
98
```
99
99
>
100
100
101
-
Here the number of columns is changed to two equal columns when the screen is 960px or smaller.
101
+
Here the number of columns is changed to two equal columns when the screen is 960px or smaller.
102
102
103
-
Test your work. resizing the page should change the display to two columns when the screen gets down to 960px and show 3 columns when the screen is wider.
103
+
Test your work. resizing the page should change the display to two columns when the screen gets down to 960px and show 3 columns when the screen is wider.
104
104
105
-
Let's do that again.
105
+
Let's do that again.
106
106
107
-
> [info]
108
-
>
107
+
> [action]
108
+
>
109
109
> Add the following to `POPOSList.css`
110
-
>
110
+
>
111
111
```CSS
112
112
/* Small screens mobile */
113
113
@mediaonlyscreenand (max-width: 700px) {
114
114
.POPOSList {
115
115
grid-template-columns: 1fr;
116
116
}
117
-
}
117
+
}
118
118
```
119
119
>
120
120
121
-
Here the the layout switched to a single column when the screen is smaller than 700px.
122
-
123
-
test your work. The screen shoould switch between 3, 2, and 1 column as the screen narrows.
124
-
125
-
Think of other things you might want to change as the screen changes size?
121
+
Here the the layout switched to a single column when the screen is smaller than 700px.
126
122
127
-
Important! In the POPOSList stylesheet you're only concerned with the list of spaces. If the changes you want to make concern the Spaces (thats' the image and text) it should be applied to the POPOSSpace.css. See the section on styling these!
123
+
test your work. The screen should switch between 3, 2, and 1 column as the screen narrows.
128
124
125
+
Think of other things you might want to change as the screen changes size?
129
126
127
+
Important! In the POPOSList stylesheet you're only concerned with the list of spaces. If the changes you want to make concern the Spaces (thats' the image and text) it should be applied to the POPOSSpace.css. See the section on styling these!
Copy file name to clipboardexpand all lines: P08-Styling-Spaces/content.md
+55-60
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,13 @@ slug: styling-spaces
5
5
6
6
## Styling Spaces
7
7
8
-
The POPOSSpace component displays a a single Public space in the list of public spaces on the home page. Each of these displays an image, the name of the space, it's address, and hours.
8
+
The POPOSSpace component displays a a single Public space in the list of public spaces on the home page. Each of these displays an image, the name of the space, it's address, and hours.
9
9
10
10
## Using ancestor selector
11
11
12
-
Styles have been divided between several style sheets. To keep these styles from conflicting you'll use the strategy of assigning the root element in a component class name that matches the component name. The Component names should be unique like class names. You should also use this class name as the ancestor for other styles applied within the component. For example:
12
+
Styles have been divided between several style sheets. To keep these styles from conflicting you'll use the strategy of assigning the root element in a component class name that matches the component name. The Component names should be unique like class names. You should also use this class name as the ancestor for other styles applied within the component. For example:
13
13
14
-
```CSS
14
+
```CSS
15
15
.POPOSSpace {
16
16
/* Styles for the root element */
17
17
}
@@ -21,29 +21,29 @@ Styles have been divided between several style sheets. To keep these styles from
21
21
}
22
22
```
23
23
24
-
The second style above styles img tags but only if they are descendants of an element with the class name: POPOSSpace. This way the styles here don't affect img tags elsewhere on the page.
24
+
The second style above styles img tags but only if they are descendants of an element with the class name: POPOSSpace. This way the styles here don't affect img tags elsewhere on the page.
25
25
26
26
## Styling POPOSSpace
27
27
28
-
Create a new stylesheet if you having. This should be a in the same folder as the `POPOSSpace.js` file.
28
+
Create a new stylesheet if you having. This should be a in the same folder as the `POPOSSpace.js` file.
29
29
30
-
> [info]
31
-
>
32
-
> Create a new file named: `POPOSSpace.css`. This should be in the same folder as the `POPOSSPace.js` file.
33
-
>
30
+
> [action]
31
+
>
32
+
> Create a new file named: `POPOSSpace.css`. This should be in the same folder as the `POPOSSPace.js` file.
33
+
>
34
34
35
-
Import the CSS and add the class name:
35
+
Import the CSS and add the class name:
36
36
37
-
> [info]
38
-
>
37
+
> [action]
38
+
>
39
39
> Add the following at the top of `POPOSSpace.js`:
40
-
>
40
+
>
41
41
```JS
42
42
import'./POPOSSpace.css'
43
43
```
44
-
>
45
-
> Now add the class to the root element:
46
-
>
44
+
>
45
+
> Now add the class to the root element:
46
+
>
47
47
```JS
48
48
functionPOPOSSpace(props) {
49
49
...
@@ -54,33 +54,31 @@ function POPOSSpace(props) {
54
54
)
55
55
}
56
56
```
57
-
>
58
57
59
-
Now you'll add some styles to style the elements here.
58
+
Now you'll add some styles to style the elements here.
60
59
61
-
It would be nice if the images were flexible. The columns of the grid change size as the page changes sizes.
60
+
It would be nice if the images were flexible. The columns of the grid change size as the page changes sizes.
62
61
63
-
> [info]
64
-
>
62
+
> [action]
63
+
>
65
64
> Add the following to: `POPOSSpace.css`:
66
-
>
65
+
>
67
66
```CSS
68
67
.POPOSSpaceimg {
69
68
width: 100%;
70
69
height: auto;
71
70
}
72
71
```
73
-
>
74
72
75
-
You might have to refresh to make sure the changes to CSS show up when testing.
73
+
You might have to refresh to make sure the changes to CSS show up when testing.
76
74
77
-
With this change the images in POPOSSpace should have a width of 100% of the available space.
75
+
With this change the images in POPOSSpace should have a width of 100% of the available space.
78
76
79
77
## Have some fun with the title
80
78
81
-
Let's move the title to the upper left corner of the picture. To do this you'll use relative and absolute position.
79
+
Let's move the title to the upper left corner of the picture. To do this you'll use relative and absolute position.
82
80
83
-
The structure of the POPOSpace is:
81
+
The structure of the POPOSpace is:
84
82
85
83
- div.POPOSSpace
86
84
- Link
@@ -90,33 +88,32 @@ The structure of the POPOSpace is:
90
88
- div (address)
91
89
- div (hours)
92
90
93
-
By making the parent component `div.POPOSSpace` position relative it will become the positioning context for any children that use absolute position. When an element uses absolute position you can position it by it's left and top edges. To figure where the top and left are the element looks up the DOM tree for an element that has `position: relative`.
91
+
By making the parent component `div.POPOSSpace` position relative it will become the positioning context for any children that use absolute position. When an element uses absolute position you can position it by it's left and top edges. To figure where the top and left are the element looks up the DOM tree for an element that has `position: relative`.
94
92
95
-
Give it a try!
93
+
Give it a try!
96
94
97
-
> [info]
98
-
>
95
+
> [action]
96
+
>
99
97
> Edit `POPOSSpace.css `, set the position property of the parent element to relative.
100
-
>
98
+
>
101
99
```CSS
102
100
.POPOSSpace {
103
101
position: relative;
104
102
}
105
103
```
106
-
>
107
104
108
-
Now add a new classname to the title element. This is in a Link component, you'll need to assign this a className.
105
+
Now add a new classname to the title element. This is in a Link component, you'll need to assign this a className.
109
106
110
-
> [info]
107
+
> [action]
108
+
>
109
+
> In `POPOSSpace.js` find the name in it's Link tag and add a new class name.
111
110
>
112
-
> In `POPOSSpace.js` find the name in it's Link tag and add a new class name.
113
-
>
114
111
```JS
115
112
functionPOPOSSpace(props) {
116
113
...
117
114
return (
118
115
...
119
-
<Link
116
+
<Link
120
117
className="POPOSSpace-title"// add a class name!
121
118
to={`/details/${id}`}>
122
119
<h1>{name}</h1>
@@ -125,14 +122,13 @@ function POPOSSpace(props) {
125
122
)
126
123
}
127
124
```
128
-
>
129
125
130
-
Next style the new class.
126
+
Next style the new class.
131
127
132
-
> [info]
133
-
>
134
-
> In `POPOSSpace.css` add some new style rules:
135
-
>
128
+
> [action]
129
+
>
130
+
> In `POPOSSpace.css` add some new style rules:
131
+
>
136
132
```CSS
137
133
.POPOSSpace.POPOSSpace-title {
138
134
display: block;
@@ -150,14 +146,14 @@ Next style the new class.
150
146
}
151
147
```
152
148
153
-
This should move the title to the upper left corner and give it some font styles.
149
+
This should move the title to the upper left corner and give it some font styles.
154
150
155
-
Now move the address and hours to the lower right corner. It will ne easier if these elements share a common parent.
151
+
Now move the address and hours to the lower right corner. It will ne easier if these elements share a common parent.
156
152
157
-
> [info]
158
-
>
159
-
> Edit `POPOSSpace.js`:
160
-
>
153
+
> [action]
154
+
>
155
+
> Edit `POPOSSpace.js`:
156
+
>
161
157
```JS
162
158
...
163
159
functionPOPOSSpace(props) {
@@ -173,31 +169,30 @@ function POPOSSpace(props) {
173
169
)
174
170
}
175
171
```
176
-
>
177
172
178
-
Now with a a parent element and a class name we can apply styles to the parent and it's children.
179
173
180
-
> [info]
181
-
>
182
-
> Edit `POPOSSpace.css` and add thw following.
183
-
>
174
+
Now with a a parent element and a class name we can apply styles to the parent and it's children.
175
+
176
+
> [action]
177
+
>
178
+
> Edit `POPOSSpace.css` and add thw following.
179
+
>
184
180
```CSS
185
181
.POPOSSpace.POPOSSpace-info {
186
182
position: absolute;
187
183
right: 0;
188
184
bottom: 0;
189
185
text-align: right;
190
-
}
186
+
}
191
187
>
192
188
.POPOSSpace.POPOSSpace-infodiv {
193
189
display: inline-block;
194
190
padding: 0.25em0.5em;
195
191
background-color: rgba(255, 255, 255, 0.9);
196
192
}
197
193
```
198
-
>
199
194
200
-
Here the container `.POPOSSpace-info` is declared position absolute This way we can place it where we want. In this case I put it at right 0 and bottom 0 which make it hug the lower right corner. I also aligned the text to the right.
201
195
202
-
The `.POPOSSpace .POPOSSpace-info div` selector applies to the two child divs. Here I added some padding and a background color.
196
+
Here the container `.POPOSSpace-info` is declared position absolute This way we can place it where we want. In this case I put it at right 0 and bottom 0 which make it hug the lower right corner. I also aligned the text to the right.
203
197
198
+
The `.POPOSSpace .POPOSSpace-info div` selector applies to the two child divs. Here I added some padding and a background color.
0 commit comments