Responsive Web Dedign(十)
freeCodeCamp —- Responsive Web Dedign
Learn Intermediate CSS by Building a Picasso Painting
Start by setting up your HTML structure. Add a
<!DOCTYPE>declaration and anhtmlelement with alangattribute set toen. Within thehtmlelement, add aheadelement and abodyelement.Within your
headelement, add ametatag with thecharsetattribute set toutf-8. Also add atitleelement with the textPicasso Painting.Go ahead and link your CSS file now, even though you have not written any CSS yet.
Add a
linkelement with arelofstylesheetand anhrefofstyles.css.FontAwesome is a library of SVG-powered icons, many of which are freely available to use. You will be using some of these icons in this project, so you will need to link the external stylesheet to your HTML.
Add a
linkelement with arelofstylesheetand anhrefofhttps://use.fontawesome.com/releases/v5.8.2/css/all.css.To get your painting started, give your
bodyelement abackground-colorofrgb(184, 132, 46).Within your body tag, add a
divelement. Give it anidofback-wall.Use an id selector to give the element with the id
back-wallabackground-colorof#8B4513.Give the
#back-wallelement awidthof100%and aheightof60%.Typically, HTML is rendered in a top-down manner. Elements at the top of the code are positioned at the top of the page. However, many times you may want to move the elements to different positions. You can do this with the
positionproperty.Set the
positionproperty for the#back-wallelement toabsolute. Anabsoluteposition takes the element out of that top-down document flow and allows you to adjust it relative to its container.When an element is manually positioned, you can shift its layout with
top,left,right, andbottom. Set the#back-wallelement to have atopvalue of0, and aleftvalue of0.The
z-indexproperty is used to create “layers” for your HTML elements. If you are familiar with image editing tools, you may have worked with layers before. This is a similar concept.Elements with a higher
z-indexvalue will appear to be layered on top of elements with a lowerz-indexvalue. This can be combined with the positioning in the previous lesson to create unique effects.Since the
back-wallelement will need to appear “behind” the other elements you will be creating, give theback-wallelement az-indexof-1.Below your
#back-wallelement, create adivwith aclassofcharacters. This is where you will be creating your painting’s characters.Inside that
.characterselement, create anotherdivwith anidofoffwhite-character.Create four
divelements inside youroffwhite-characterelement. Give thosedivelements the followingidvalues, in order:white-hat,black-mask,gray-instrument,tan-table.This character needs eyes. Create two
divelements in the#black-maskelement. Give them the classeseyes leftandeyes right, in that order.Create some “dots” for the instrument. Add five
divelements within your#gray-instrumentelement. Set theclassof each toblack-dot.Using an id selector, create a rule for the element with the id
offwhite-character. Give it awidthof300px, aheightof550px, and abackground-colorofGhostWhite.Move the
#offwhite-characterinto place by giving it apositionofabsolute, atopvalue of20%, and aleftvalue of17.5%.Using an id selector, style the element with the id
white-hat. Give it awidthandheightof0, and aborder-styleofsolid.That does not look quite right. Set a
border-widthof0 120px 140px 180pxto size the hat properly.Now you have a large box. Give it a
border-top-color,border-right-color, andborder-left-coloroftransparent. Set theborder-bottom-colortoGhostWhite. This will make it look more like a hat.Give the hat a
positionofabsolute, atopvalue of-140px, and aleftvalue of0.Using an id selector, create a rule for the element with the id
black-mask. Give it awidthof100%, aheightof50px, and abackground-colorofrgb(45, 31, 19).Give the mask a
positionofabsolute, and atopandleftvalue of0.To ensure you can see the mask, give it a
z-indexof1.Using an id selector, give the element with the id
gray-instrumentawidthof15%, aheightof40%, and abackground-colorofrgb(167, 162, 117).Now move it into place with a
positionofabsolute, atopvalue of50px, and aleftvalue of125px.Set the
z-indexto1.Use a class selector to create a rule for the elements with
black-dotclass. Set thewidthto10px, theheightto10px, and thebackground-colortorgb(45, 31, 19).These dots are just a little too square. Give the
black-dotclass aborder-radiusof50%to fix it.These dots are just a little too square. Give the
black-dotclass aborder-radiusof50%to fix it.Use an id selector to style the element with the id
tan-table. Give it awidthof450px, aheightof140px, and abackground-colorof#D2691E.Move the table into place by giving it a
positionofabsolute, atopvalue of275px, and aleftvalue of15px.Give the table a
z-indexof1.After your
div#offwhite-characterelement, add adivwith theidofblack-character.Within your new
#black-characterelement, add threedivelements with the followingidvalues, in order:black-hat,gray-mask,white-paper.The mask needs eyes. Within your
#gray-maskelement, add twodivelements. The first should have theclassset toeyes left, and the second should have theclassset toeyes right.Time to use some FontAwesome icons.
The
ielement is used for idiomatic text, or text that is separate from the “normal” text content. This could be for italic text, such as scientific terms, or for icons like those provided by FontAwesome.Within your
#white-paperelement, add fourielements. Give them all aclassvalue offas fa-music.This special class is how FontAwesome determines which icon to load.
fasindicates the category of icons (FontAwesome Solid, here), whilefa-musicselects the specific icon.Use an id selector to create a rule for the element with the id
black-character. Set thewidthto300px, theheightto500px, and thebackground-colortorgb(45, 31, 19).Move the
#black-characterelement into place by setting thepositiontoabsolute, thetopto30%, and theleftto59%.Use an id selector to create a rule for the element with the id
black-hat. Give it awidthof0, aheightof0, and aborder-styleofsolid.Set the
border-widthof the#black-hatto150px 0 0 300px.Just like with your
#white-hat, you should style the border for the#black-hatelement. Give it aborder-top-color,border-right-color, andborder-bottom-coloroftransparent. Set theborder-left-colortorgb(45, 31, 19).Now position the
#black-hatelement. Give it apositionofabsolute, with atopof-150pxand aleftof0.Using an id selector, style the element with the id
gray-mask. Give it awidthof150px, aheightof150px, and abackground-colorofrgb(167, 162, 117).Position the
#gray-maskelement by settingpositiontoabsolute, thetopto-10px, and theleftto70px.Using an id selector, create a rule for the id
white-paper. Set thewidthto400px, theheightto100px, and thebackground-colortoGhostWhite.Give the
#white-paperapositionofabsolute, atopof250px, and aleftof-150pxto move it into place.Set the
z-indexof the#white-paperelement to1.FontAwesome icons come with their own styling to define the icon. However, you can still set the styling yourself as well, to change things like the color and size. For now, use a class selector to target the icons with the class
fa-music. Set thedisplaytoinline-block, themargin-topto8%, and themargin-leftto13%.Below your
#black-characterelement, add two newdivelements. These will be the shawl. Give both of them aclassofblue. Then give the first one anidofblue-left, and the second anidofblue-right.Use a class selector to target the new elements with the class
blue. Set thebackground-colorto#1E90FF.Select the element with the id
blue-leftusing an id selector. Give it awidthof500pxand aheightof300px.Now set the
positiontoabsolute, thetopto20%, and theleftto20%.Next, target the element with the id
blue-rightusing an id selector. Set thewidthto400pxand theheightto300px.Give the
#blue-rightelement the correct positioning withpositionset toabsolute,topset to50%, andleftset to40%.Below your
.blueelements, add anotherdiv. Give it theidvalue oforange-character.Within that
#orange-characterelement, add fourdivelements. Give them theidvalues ofblack-round-hat,eyes-div,triangles, andguitar, in order.The
#eyes-divelement should hold some eyes. Add twodivelements inside. Give the first aclassofeyes left, and give the second aclassofeyes right.Within the
#trianglesdiv, you will need to add the elements that will become your triangles. Create thirtydivelements and give each of them the classtriangle.Within the
#guitarelement, create threedivelements. Give the first two aclassvalue ofguitar. Then give the first anidofguitar-left, and the second anidofguitar-right. Add anidto the thirddivwith the valueguitar-neck.The third
divshould not have theguitarclass.Use another FontAwesome icon for your
.guitar. Inside both the#guitar-leftand#guitar-rightelements, add anielement and give it aclassoffas fa-bars.Select your
orange-characterelement with an id selector. Give it awidthof250px, aheightof550px, and abackground-colorofrgb(240, 78, 42).Give the
#orange-characterelement apositionofabsolute, atopof25%, and aleftof40%.Give the
#orange-characterelement apositionofabsolute, atopof25%, and aleftof40%.The
#black-round-hatelement should probably be round. Give it aborder-radiusof50%to fix this.Move the
#black-round-hatelement into place with apositionofabsolute, atopof-100px, and aleftof5px.Put the
#black-round-hatelement on the correct layer with az-indexof-1.Use an id selector to create a rule for the element with the id
eyes-div. Set thewidthto180pxand theheightto50px.Now move the
#eyes-divelement into position withpositionset toabsolute,topset to-40px, andleftset to20px.Give the
#eyes-divelement az-indexof3.Target the element with the id
trianglesusing an id selector. Set thewidthto250pxand theheightto550px.Create a class selector for the elements with the
triangleclass. Set thewidthto0and theheightto0.Style the border of your
.triangleelements. Set theborder-styletosolidand theborder-widthto42px 45px 45px 0.Give your
.triangleelements the correct color. Set theborder-top-color,border-bottom-color, andborder-left-colortotransparent. Set theborder-right-colortoGold.Adjust the layout of the
.triangleelements with adisplayofinline-block.Now use an id selector for
guitar. Set thewidthto100%, and theheightto100px.In the same
#guitarselector, set thepositiontoabsolute, thetopto120px, and theleftto0px.Give the
#guitarrule az-indexof3.Now use a class selector to target
guitar. This will style the two “halves” of your guitar. Set thewidthto150px, theheightto120px, thebackground-colortoGoldenrod, and theborder-radiusto50%.Select the
idwith valueguitar-left, and set thepositiontoabsoluteand theleftto0px.Select the
idwith valueguitar-right, and also setpositiontoabsolute. This time, setleftto100px.Now you need to move the bar icons into place. Create a class selector for the
fa-barsclass. Set thedisplaytoblock, themargin-topto30%, and themargin-leftto40%.Use an id selector to create a rule for the id
guitar-neck. Set thewidthto200px, theheightto30px, and thebackground-colorto#D2691E.Now move the
#guitar-neckelement with apositionofabsolute, atopvalue of45px, and aleftvalue of200px.Give the
#guitar-neckelement az-indexof3.Time to style the elements with the
eyesclass. Use a class selector to set thewidthto35px, theheightto20px, thebackground-colorto#8B4513, and theborder-radiusto20px 50%.Target the
classwith valuerightand set thepositiontoabsolute,topto15px, andrightto30px.For the
classwith valueleft, create the selector and set thepositiontoabsolute, thetopto15px, and theleftto30px.One last step. The FontAwesome icons are a little too small. Target all of them with a class selector for
fas, and set thefont-sizeto30px.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<html lang="en">
<head>
<meta charset="utf-8">
<title>Picasso Painting</title>
<link rel="stylesheet" href="./styles.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
</head>
<body>
<div id="back-wall"></div>
<div class="characters">
<div id="offwhite-character">
<div id="white-hat"></div>
<div id="black-mask">
<div class="eyes left"></div>
<div class="eyes right"></div>
</div>
<div id="gray-instrument">
<div class="black-dot"></div>
<div class="black-dot"></div>
<div class="black-dot"></div>
<div class="black-dot"></div>
<div class="black-dot"></div>
</div>
<div id="tan-table"></div>
</div>
<div id="black-character">
<div id="black-hat"></div>
<div id="gray-mask">
<div class="eyes left"></div>
<div class="eyes right"></div>
</div>
<div id="white-paper">
<i class="fas fa-music"></i>
<i class="fas fa-music"></i>
<i class="fas fa-music"></i>
<i class="fas fa-music"></i>
</div>
</div>
<div class="blue" id="blue-left"></div>
<div class="blue" id="blue-right"></div>
<div id="orange-character">
<div id="black-round-hat"></div>
<div id="eyes-div">
<div class="eyes left"></div>
<div class="eyes right"></div>
</div>
<div id="triangles">
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
<div class="triangle"></div>
</div>
<div id="guitar">
<div class="guitar" id="guitar-left">
<i class="fas fa-bars"></i>
</div>
<div class="guitar" id="guitar-right">
<i class="fas fa-bars"></i>
</div>
<div id="guitar-neck"></div>
</div>
</div>
</div>
</body>
</html>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254body {
background-color: rgb(184, 132, 46);
}
#back-wall {
background-color: #8B4513;
width: 100%;
height: 60%;
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
#offwhite-character {
width: 300px;
height: 550px;
background-color: GhostWhite;
position: absolute;
top: 20%;
left: 17.5%;
}
#white-hat {
width: 0;
height: 0;
border-style: solid;
border-width: 0 120px 140px 180px;
border-top-color: transparent;
border-right-color: transparent;
border-bottom-color: GhostWhite;
border-left-color: transparent;
position: absolute;
top: -140px;
left: 0;
}
#black-mask {
width: 100%;
height: 50px;
background-color: rgb(45, 31, 19);
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
#gray-instrument {
width: 15%;
height: 40%;
background-color: rgb(167, 162, 117);
position: absolute;
top: 50px;
left: 125px;
z-index: 1;
}
.black-dot {
width: 10px;
height: 10px;
background-color: rgb(45, 31, 19);
border-radius: 50%;
display: block;
margin: auto;
margin-top: 65%;
}
#tan-table {
width: 450px;
height: 140px;
background-color: #D2691E;
position: absolute;
top: 275px;
left: 15px;
z-index: 1;
}
#black-character {
width: 300px;
height: 500px;
background-color: rgb(45, 31, 19);
position: absolute;
top: 30%;
left: 59%;
}
#black-hat {
width: 0;
height: 0;
border-style: solid;
border-width: 150px 0 0 300px;
border-top-color: transparent;
border-right-color: transparent;
border-bottom-color: transparent;
border-left-color: rgb(45, 31, 19);
position: absolute;
top: -150px;
left: 0;
}
#gray-mask {
width: 150px;
height: 150px;
background-color: rgb(167, 162, 117);
position: absolute;
top: -10px;
left: 70px;
}
#white-paper {
width: 400px;
height: 100px;
background-color: GhostWhite;
position: absolute;
top: 250px;
left: -150px;
z-index: 1;
}
.fa-music {
display: inline-block;
margin-top: 8%;
margin-left: 13%;
}
.blue {
background-color: #1E90FF;
}
#blue-left {
width: 500px;
height: 300px;
position: absolute;
top: 20%;
left: 20%;
}
#blue-right {
width: 400px;
height: 300px;
position: absolute;
top: 50%;
left: 40%;
}
#orange-character {
width: 250px;
height: 550px;
background-color: rgb(240, 78, 42);
position: absolute;
top: 25%;
left: 40%;
}
#black-round-hat {
width: 180px;
height: 150px;
background-color: rgb(45, 31, 19);
border-radius: 50%;
position: absolute;
top: -100px;
left: 5px;
z-index: -1;
}
#eyes-div {
width: 180px;
height: 50px;
position: absolute;
top: -40px;
left: 20px;
z-index: 3;
}
#triangles {
width: 250px;
height: 550px;
}
.triangle {
width: 0;
height: 0;
border-style: solid;
border-width: 42px 45px 45px 0;
border-top-color: transparent;
border-right-color: Gold; /* yellow */
border-bottom-color: transparent;
border-left-color: transparent;
display: inline-block;
}
#guitar {
width: 100%;
height: 100px;
position: absolute;
top: 120px;
left: 0px;
z-index: 3;
}
.guitar {
width: 150px;
height: 120px;
background-color: Goldenrod;
border-radius: 50%;
}
#guitar-left {
position: absolute;
left: 0px;
}
#guitar-right {
position: absolute;
left: 100px;
}
.fa-bars {
display: block;
margin-top: 30%;
margin-left: 40%;
}
#guitar-neck {
width: 200px;
height: 30px;
background-color: #D2691E;
position: absolute;
top: 45px;
left: 200px;
z-index: 3;
}
.eyes {
width: 35px;
height: 20px;
background-color: #8B4513;
border-radius: 20px 50%;
}
.right {
position: absolute;
top: 15px;
right: 30px;
}
.left {
position: absolute;
top: 15px;
left: 30px;
}
.fas{
font-size:30px;
}真丑啊!!!