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 anhtml
element with alang
attribute set toen
. Within thehtml
element, add ahead
element and abody
element.Within your
head
element, add ameta
tag with thecharset
attribute set toutf-8
. Also add atitle
element with the textPicasso Painting
.Go ahead and link your CSS file now, even though you have not written any CSS yet.
Add a
link
element with arel
ofstylesheet
and anhref
ofstyles.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
link
element with arel
ofstylesheet
and anhref
ofhttps://use.fontawesome.com/releases/v5.8.2/css/all.css
.To get your painting started, give your
body
element abackground-color
ofrgb(184, 132, 46)
.Within your body tag, add a
div
element. Give it anid
ofback-wall
.Use an id selector to give the element with the id
back-wall
abackground-color
of#8B4513
.Give the
#back-wall
element awidth
of100%
and aheight
of60%
.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
position
property.Set the
position
property for the#back-wall
element toabsolute
. Anabsolute
position 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-wall
element to have atop
value of0
, and aleft
value of0
.The
z-index
property 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-index
value will appear to be layered on top of elements with a lowerz-index
value. This can be combined with the positioning in the previous lesson to create unique effects.Since the
back-wall
element will need to appear “behind” the other elements you will be creating, give theback-wall
element az-index
of-1
.Below your
#back-wall
element, create adiv
with aclass
ofcharacters
. This is where you will be creating your painting’s characters.Inside that
.characters
element, create anotherdiv
with anid
ofoffwhite-character
.Create four
div
elements inside youroffwhite-character
element. Give thosediv
elements the followingid
values, in order:white-hat
,black-mask
,gray-instrument
,tan-table
.This character needs eyes. Create two
div
elements in the#black-mask
element. Give them the classeseyes left
andeyes right
, in that order.Create some “dots” for the instrument. Add five
div
elements within your#gray-instrument
element. Set theclass
of each toblack-dot
.Using an id selector, create a rule for the element with the id
offwhite-character
. Give it awidth
of300px
, aheight
of550px
, and abackground-color
ofGhostWhite
.Move the
#offwhite-character
into place by giving it aposition
ofabsolute
, atop
value of20%
, and aleft
value of17.5%
.Using an id selector, style the element with the id
white-hat
. Give it awidth
andheight
of0
, and aborder-style
ofsolid
.That does not look quite right. Set a
border-width
of0 120px 140px 180px
to size the hat properly.Now you have a large box. Give it a
border-top-color
,border-right-color
, andborder-left-color
oftransparent
. Set theborder-bottom-color
toGhostWhite
. This will make it look more like a hat.Give the hat a
position
ofabsolute
, atop
value of-140px
, and aleft
value of0
.Using an id selector, create a rule for the element with the id
black-mask
. Give it awidth
of100%
, aheight
of50px
, and abackground-color
ofrgb(45, 31, 19)
.Give the mask a
position
ofabsolute
, and atop
andleft
value of0
.To ensure you can see the mask, give it a
z-index
of1
.Using an id selector, give the element with the id
gray-instrument
awidth
of15%
, aheight
of40%
, and abackground-color
ofrgb(167, 162, 117)
.Now move it into place with a
position
ofabsolute
, atop
value of50px
, and aleft
value of125px
.Set the
z-index
to1
.Use a class selector to create a rule for the elements with
black-dot
class. Set thewidth
to10px
, theheight
to10px
, and thebackground-color
torgb(45, 31, 19)
.These dots are just a little too square. Give the
black-dot
class aborder-radius
of50%
to fix it.These dots are just a little too square. Give the
black-dot
class aborder-radius
of50%
to fix it.Use an id selector to style the element with the id
tan-table
. Give it awidth
of450px
, aheight
of140px
, and abackground-color
of#D2691E
.Move the table into place by giving it a
position
ofabsolute
, atop
value of275px
, and aleft
value of15px
.Give the table a
z-index
of1
.After your
div#offwhite-character
element, add adiv
with theid
ofblack-character
.Within your new
#black-character
element, add threediv
elements with the followingid
values, in order:black-hat
,gray-mask
,white-paper
.The mask needs eyes. Within your
#gray-mask
element, add twodiv
elements. The first should have theclass
set toeyes left
, and the second should have theclass
set toeyes right
.Time to use some FontAwesome icons.
The
i
element 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-paper
element, add fouri
elements. Give them all aclass
value offas fa-music
.This special class is how FontAwesome determines which icon to load.
fas
indicates the category of icons (FontAwesome Solid, here), whilefa-music
selects the specific icon.Use an id selector to create a rule for the element with the id
black-character
. Set thewidth
to300px
, theheight
to500px
, and thebackground-color
torgb(45, 31, 19)
.Move the
#black-character
element into place by setting theposition
toabsolute
, thetop
to30%
, and theleft
to59%
.Use an id selector to create a rule for the element with the id
black-hat
. Give it awidth
of0
, aheight
of0
, and aborder-style
ofsolid
.Set the
border-width
of the#black-hat
to150px 0 0 300px
.Just like with your
#white-hat
, you should style the border for the#black-hat
element. Give it aborder-top-color
,border-right-color
, andborder-bottom-color
oftransparent
. Set theborder-left-color
torgb(45, 31, 19)
.Now position the
#black-hat
element. Give it aposition
ofabsolute
, with atop
of-150px
and aleft
of0
.Using an id selector, style the element with the id
gray-mask
. Give it awidth
of150px
, aheight
of150px
, and abackground-color
ofrgb(167, 162, 117)
.Position the
#gray-mask
element by settingposition
toabsolute
, thetop
to-10px
, and theleft
to70px
.Using an id selector, create a rule for the id
white-paper
. Set thewidth
to400px
, theheight
to100px
, and thebackground-color
toGhostWhite
.Give the
#white-paper
aposition
ofabsolute
, atop
of250px
, and aleft
of-150px
to move it into place.Set the
z-index
of the#white-paper
element 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 thedisplay
toinline-block
, themargin-top
to8%
, and themargin-left
to13%
.Below your
#black-character
element, add two newdiv
elements. These will be the shawl. Give both of them aclass
ofblue
. Then give the first one anid
ofblue-left
, and the second anid
ofblue-right
.Use a class selector to target the new elements with the class
blue
. Set thebackground-color
to#1E90FF
.Select the element with the id
blue-left
using an id selector. Give it awidth
of500px
and aheight
of300px
.Now set the
position
toabsolute
, thetop
to20%
, and theleft
to20%
.Next, target the element with the id
blue-right
using an id selector. Set thewidth
to400px
and theheight
to300px
.Give the
#blue-right
element the correct positioning withposition
set toabsolute
,top
set to50%
, andleft
set to40%
.Below your
.blue
elements, add anotherdiv
. Give it theid
value oforange-character
.Within that
#orange-character
element, add fourdiv
elements. Give them theid
values ofblack-round-hat
,eyes-div
,triangles
, andguitar
, in order.The
#eyes-div
element should hold some eyes. Add twodiv
elements inside. Give the first aclass
ofeyes left
, and give the second aclass
ofeyes right
.Within the
#triangles
div, you will need to add the elements that will become your triangles. Create thirtydiv
elements and give each of them the classtriangle
.Within the
#guitar
element, create threediv
elements. Give the first two aclass
value ofguitar
. Then give the first anid
ofguitar-left
, and the second anid
ofguitar-right
. Add anid
to the thirddiv
with the valueguitar-neck
.The third
div
should not have theguitar
class.Use another FontAwesome icon for your
.guitar
. Inside both the#guitar-left
and#guitar-right
elements, add ani
element and give it aclass
offas fa-bars
.Select your
orange-character
element with an id selector. Give it awidth
of250px
, aheight
of550px
, and abackground-color
ofrgb(240, 78, 42)
.Give the
#orange-character
element aposition
ofabsolute
, atop
of25%
, and aleft
of40%
.Give the
#orange-character
element aposition
ofabsolute
, atop
of25%
, and aleft
of40%
.The
#black-round-hat
element should probably be round. Give it aborder-radius
of50%
to fix this.Move the
#black-round-hat
element into place with aposition
ofabsolute
, atop
of-100px
, and aleft
of5px
.Put the
#black-round-hat
element on the correct layer with az-index
of-1
.Use an id selector to create a rule for the element with the id
eyes-div
. Set thewidth
to180px
and theheight
to50px
.Now move the
#eyes-div
element into position withposition
set toabsolute
,top
set to-40px
, andleft
set to20px
.Give the
#eyes-div
element az-index
of3
.Target the element with the id
triangles
using an id selector. Set thewidth
to250px
and theheight
to550px
.Create a class selector for the elements with the
triangle
class. Set thewidth
to0
and theheight
to0
.Style the border of your
.triangle
elements. Set theborder-style
tosolid
and theborder-width
to42px 45px 45px 0
.Give your
.triangle
elements the correct color. Set theborder-top-color
,border-bottom-color
, andborder-left-color
totransparent
. Set theborder-right-color
toGold
.Adjust the layout of the
.triangle
elements with adisplay
ofinline-block
.Now use an id selector for
guitar
. Set thewidth
to100%
, and theheight
to100px
.In the same
#guitar
selector, set theposition
toabsolute
, thetop
to120px
, and theleft
to0px
.Give the
#guitar
rule az-index
of3
.Now use a class selector to target
guitar
. This will style the two “halves” of your guitar. Set thewidth
to150px
, theheight
to120px
, thebackground-color
toGoldenrod
, and theborder-radius
to50%
.Select the
id
with valueguitar-left
, and set theposition
toabsolute
and theleft
to0px
.Select the
id
with valueguitar-right
, and also setposition
toabsolute
. This time, setleft
to100px
.Now you need to move the bar icons into place. Create a class selector for the
fa-bars
class. Set thedisplay
toblock
, themargin-top
to30%
, and themargin-left
to40%
.Use an id selector to create a rule for the id
guitar-neck
. Set thewidth
to200px
, theheight
to30px
, and thebackground-color
to#D2691E
.Now move the
#guitar-neck
element with aposition
ofabsolute
, atop
value of45px
, and aleft
value of200px
.Give the
#guitar-neck
element az-index
of3
.Time to style the elements with the
eyes
class. Use a class selector to set thewidth
to35px
, theheight
to20px
, thebackground-color
to#8B4513
, and theborder-radius
to20px 50%
.Target the
class
with valueright
and set theposition
toabsolute
,top
to15px
, andright
to30px
.For the
class
with valueleft
, create the selector and set theposition
toabsolute
, thetop
to15px
, and theleft
to30px
.One last step. The FontAwesome icons are a little too small. Target all of them with a class selector for
fas
, and set thefont-size
to30px
.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;
}真丑啊!!!