-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path07-css-box-model.html
More file actions
409 lines (339 loc) · 17.8 KB
/
07-css-box-model.html
File metadata and controls
409 lines (339 loc) · 17.8 KB
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS box model</title>
<meta name="description" content="CSS Box Model">
<meta name="author" content="Code with me, Tom Giratikanon, Sisi Wei">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link href='http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/theme/default.css">
<link rel="stylesheet" href="css/codewithme.css">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<script>
// If the query includes 'print-pdf' we'll use the PDF print sheet
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Used to fade in a background when a specific slide state is reached -->
<div class="state-background"></div>
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section class="small">
<h1 class="opening special-margin">The CSS box model</h1>
<div class="small-logo-container disappear">
<img src="images/basic-logo-tan-bg.png"/>
<div class="copyright">© <span>2013</span></div>
</div>
<div class="notes">
<p>
As you've begun to style CSS, you've probably wanted to do things like add borders, or spacing, or drop shadows, around your paragraphs and headlines. That's done through what's called the box model.
</p>
<p>
Why is it the "box" model? Because the structure of HTML elements is a box. If you inspect an element, it's always rectangular, and often wider than the text within it.
</p>
</div>
</section>
<section>
<h2 class="vertical-center">What the Box Model can do</h2>
<h3 style="margin-top:20px;"><a href="http://www.grantland.com/story/_/id/9175394/out-great-alone">Out in the Great Alone</a></h3>
</section>
<section>
<div class="stack" style="width: 700px">
<div class="layer">
<img src="images/presentations/box-model/basic.png" alt="">
</div>
<div class="layer fragment">
<img src="images/presentations/box-model/annotated.png" alt="">
</div>
</div>
</section>
<section>
<h1 class="vertical-center">Width</h1>
<center>
<div class="width" style="width:220px;">
<span class="border left"></span>
<hr style="width:215px;">
<span class="border right"></span>
</div>
</center>
<div class="clear"></div>
<p>215px</p>
</section>
<section>
<p class="vertical-center">All text on a webpage is within a box. All boxes have a width.</p>
<center>
<div class="width" style="width:935px;">
<span class="border left"></span>
<hr style="width:930px;">
<span class="border right"></span>
</div>
</center>
<div class="clear"></div>
<p>930px</p>
</section>
<section>
<center>
<p style="width: 250px; margin-top:13%;">Set the width of the box differently and your text will oblige.</p>
<div class="width" style="width:255px;">
<span class="border left"></span>
<hr style="width:250px;">
<span class="border right"></span>
</div>
</center>
<div class="clear"></div>
<p class="fragment">width: 250px;</p>
</section>
<section>
<h1 class="vertical-center" style="border:20px solid #d8d4af;">Border</h1>
</section>
<section>
<div style="float:left; margin-top:5%;">
<p style="border:100px solid #d8d4af; width: 250px;">Sometimes, I'd like my text to have a big old border.</p>
<p class="fragment" style="margin-top:20px; font-size:30px; color: #919191;">border: <strong style="color:black;">100px</strong> solid #d8d4af;</p>
</div>
<div style="margin:15% 0 0 30px; float:left;">
<p style="border:10px solid #d8d4af; width: 400px; ">Other times I want to tone it down.</p>
<p class="fragment" style="margin-top:20px; font-size:30px; color: #919191;">border: <strong style="color:black;">10px</strong> solid #d8d4af;</p>
</div>
<div class="clear"></div>
</section>
<section class="border-options">
<div style="float:left; margin-left:15%;">
<p style="border:10px solid #d8d4af; width: 250px;">Most of the time I'm solid.</p>
<p style="border:10px dashed #d8d4af; width: 250px;">On occassion I want to look like a coupon.</p>
<p style="border:10px groove #d8d4af; width: 250px;">Most of these are out of style.</p>
<p style="border:10px inset #d8d4af; width: 250px;">But you can tell I've got options.</p>
</div>
<div style="float:left; font-size: 25px; margin-left: 30px; text-align:left;">
<p style="height: 76px; padding-top:30px; color: #919191;">border:10px <strong style="color:black;">solid </strong>#d8d4af;</p>
<p class="fragment" style="height: 99px; padding-top:50px; color: #919191;">border:10px <strong style="color:black;">dashed</strong> #d8d4af;</p>
<p class="fragment" style="height: 76px; padding-top:30px; color: #919191;">border:10px <strong style="color:black;">groove</strong> #d8d4af;</p>
<p class="fragment" style="height: 76px; padding-top:30px; color: #919191;">border:10px <strong style="color:black;">inset </strong>#d8d4af;</p>
</div>
</section>
<section>
<center>
<p style="border:10px solid #d8d4af; width: 400px; margin-top:20%;">But listen, the border is really cramping my style. Get a little further away from the text, would'ya?</p>
</center>
</section>
<section>
<h1 style="border:20px solid #d8d4af; padding: 50px; margin-top: 15%">Padding</h1>
<p>(Scaring away borders since ... 20 years ago)</p>
</section>
<section>
<center>
<p style="border:10px solid #d8d4af; width: 400px; margin-top:20%; padding: 50px;">Phew. Now I've got some room to breathe.</p>
<p class="fragment">padding: 50px;</p>
</center>
</section>
<section>
<div style="margin:20% 0 0 0; float:right;">
<p style="border:10px solid #00b29e; width: 300px; padding: 10px; font-size: 28px;">Hi Dad. <br/>Can you uh, not hug me every time you see me?</p>
</div>
<p style="border:10px solid #d8d4af; width: 350px; margin-top:20%; padding: 50px; float:right;">Oh look! <br/>It's my daughter Sisi!</p>
</section>
<section>
<h1 style="border:20px solid #d8d4af; margin: 10% 0 200px 0;">Margin</h1>
<p>(Your line of defense when other boxes stand too close.)</p>
</section>
<section>
<p style="border:10px solid #00b29e; width: 300px; margin-top:20%; padding: 10px; float:right;">Listen, you just gotta move over.</p>
<p style="background-color: white; width: 80px; margin-top:20%; float:right; height: 127px;"></p>
<p style="border:10px solid #d8d4af; width: 400px; margin-top:20%; padding: 50px; float:right;">Wait a second...</p>
<div class="clear"></div>
<p style="margin-top: 50px;">(Sisi used her power "margin-left:80px"!)</p>
</section>
<section>
<center>
<p style="border:10px solid #d8d4af; width: 400px; padding: 30px; margin:10% 0 0 0;">Hi Sisi!</p>
<div>
<p style="border:10px solid #d8d4af; width: 155px; padding: 30px; float:left; margin:0px;">Hi Sisi!</p>
<p style="border:10px solid #00b29e; width: 400px; padding: 30px; float:left; margin:0px;">Oh no, family reunion.</p>
<p style="border:10px solid #d8d4af; width: 155px; padding: 30px; float:left; margin:0px;">Hi Sisi!</p>
</div>
<div class="clear"></div>
<p style="border:10px solid #d8d4af; width: 400px; padding: 30px; margin:0px;">Hi Sisi!</p>
<p style="margin-top: 50px;">(What should I do?)</p>
</center>
</section>
<section>
<center>
<p style="border:10px solid #d8d4af; width: 400px; padding: 30px; margin:0px;">Hi Sisi!</p>
<p style="background-color: white; width: 480px; height: 50px; margin:0px;"></p>
<div>
<p style="border:10px solid #d8d4af; width: 125px; padding: 30px 20px; float:left; margin:0px;">Hi Sisi!</p>
<p style="background-color: white; width: 50px; height: 122px; margin:0px; float:left;"></p>
<p style="border:10px solid #00b29e; width: 400px; padding: 30px; float:left; margin:0px;">Margin power!</p>
<p style="background-color: white; width: 50px; height: 122px; margin:0px; float:left;"></p>
<p style="border:10px solid #d8d4af; width: 125px; padding: 30px 20px; float:left; margin:0px;">Hi Sisi!</p>
</div>
<div class="clear"></div>
<p style="background-color: white; width: 480px; height: 50px; margin:0px;"></p>
<p style="border:10px solid #d8d4af; width: 400px; padding: 30px; margin:0px;">Hi Sisi!</p>
<p style="margin-top: 50px;">margin: 50px;</p>
</center>
</section>
<section class="small">
<center>
<p style="border:10px solid #d8d4af; width: 400px; padding: 30px; margin:0 0 50px 0;">Hi Sisi!</p>
<div>
<p style="border:10px solid #d8d4af; width: 125px; padding: 30px 20px; float:left; margin:0px;">Hi Sisi!</p>
<p style="border:10px solid #00b29e; width: 400px; padding: 30px; float:left; margin:0px 50px;">Margin power!</p>
<p style="border:10px solid #d8d4af; width: 125px; padding: 30px 20px; float:left; margin:0px;">Hi Sisi!</p>
</div>
<div class="clear"></div>
<p style="border:10px solid #d8d4af; width: 400px; padding: 30px; margin:50px 0 0 0;">Hi Sisi!</p>
<p style="margin-top: 50px;">margin: 50px;</p>
</center>
<div class="notes">
<p>But margins don't have color, so in reality it looks like this. Okay, so let's review.</p>
</div>
</section>
<section>
<h2>Width, margin, border, padding</h2>
<div class="box-model-container">
<img src="images/box-model.png" />
<div class="notes">
<p>So here are all the parts of the model? (Review all) </p>
<p>If you need help remembering, just imagine a puffy dress -- the padding is the stuff on the inside of the dress, the border is the hemline, and the margin is the space between each person. The person, like the content, is the in the center.</p>
<p>So let's review the syntax of how to actually use the model.</p>
</div>
</div>
</section>
<section class="small">
<h2>Let's look at some syntax</h2>
<ul>
<li class="syntax">margin-top: 20px;</li>
<li class="syntax fragment">margin-right: 20px;</li>
<li class="syntax fragment">padding-right: 20px;</li>
<li class="syntax fragment">border-right: 1px dotted black;</li>
<li class="syntax fragment">margin: 20px 30px 40p 50px;</li>
<li class="syntax fragment">margin: <em>top right bottom left (TRBL)</em></li>
</ul>
<div class="notes">
<p>(Walk through bullet points. Ask students if they can predict what would happen.)</p>
<p>Any questions on the box model?</p>
<p>So I want to cover one topic related to the box model.</p>
</div>
</section>
<section class="small">
<h2>Organizing your elements</h2>
<p> </p>
<div class="plain browser disappear">
<h3>As Not Seen on TV</h3>
<img src="http://graphics8.nytimes.com/images/2012/11/14/dining/14REST1_SPAN/14REST1_SPAN-articleLarge.jpg" alt="" width=300>
<p>By PETE WELLS</p>
<p>GUY FIERI, have you eaten at your new restaurant in Times Square? Have you pulled up one of the 500 seats at Guy’s American Kitchen & Bar and ordered a meal? Did you eat the food? Did it live up to your expectations?</p>
</div>
<div class="notes">
<p>On the web, we often have a collection of paragraphs or images that we want to bundle together. Like an article, or a headline and a photo. We often want one border to go around them, or to have some margin around an entire set of items -- we want them to feel connected and cohesive.</p>
<p>In terms of HTML, we need to put them into a single box. How do we do that? We can't use a paragraph -- they can't contain multiple paragraphs.</p>
<p>So we use what's called a div, or divider, like a bookshelf, to hold lots of little things in place.</p>
</div>
</section>
<section class="small">
<!-- <h2>We need a div!</h2> -->
<div class="disappear half first">
<pre><code><div>
<h3>As Not Seen on TV</h3>
<img src="http://i.imgur.com/EOUpanD.jpg">
<p>GUY FIERI, have you eaten at your new restaurant in Times Square? Have you pulled up one of the 500 seats at Guy’s American Kitchen & Bar and ordered a meal? Did you eat the food? </p>
</div></code></pre>
</div>
<div class="plain half browser">
<h3>As Not Seen on TV</h3>
<img src="http://graphics8.nytimes.com/images/2012/11/14/dining/14REST1_SPAN/14REST1_SPAN-articleLarge.jpg" alt="" width=350>
<p>GUY FIERI, have you eaten at your new restaurant in Times Square? Have you pulled up one of the 500 seats at Guy’s American Kitchen & Bar and ordered a meal? Did you eat the food? </p>
</div>
<div class="notes">
<p>So, we can put all of that content into a single div. Now we can style the div as one unit -- we can add a margin, border, padding, whatever. </p>
<p>It's like how by moving a bookshelf, we can move everything in it without dealing with each piece.</p>
<p>Note how we're writing the code too: everything in the div is indented, and the opening and closing div tags line up. Programmers keep their code structured because it helps them see the structure of the page -- you can imagine the boxes.</p>
</div>
</section>
<section class="small">
<!-- <h2>We need a div!</h2> -->
<div class="disappear half first">
<div class="stacked-editor">
<p>styles.css</p>
<pre ><code>.article {
width: 400px;
padding: 20px;
border: 3px solid #ccc;
} </code></pre>
</div>
<div class="stacked-editor">
<p>index.html</p>
<pre><code><div class="article">
<h3>As Not Seen on TV</h3>
<img src="http://i.imgur.com/EOUpanD.jpg">
<p>GUY FIERI, have you eaten at your new restaurant in Times Square? ... </p>
</div></code></pre>
</div>
</div>
<div class="plain half browser">
<div class="article">
<h3>As Not Seen on TV</h3>
<img src="http://graphics8.nytimes.com/images/2012/11/14/dining/14REST1_SPAN/14REST1_SPAN-articleLarge.jpg" alt="" width=350>
<p>GUY FIERI, have you eaten at your new restaurant in Times Square? Have you pulled up one of the 500 seats at Guy’s American Kitchen & Bar and ordered a meal? Did you eat the food? </p>
</div>
</div>
<div class="notes">
<p>So, we can put all of that content into a single div. Now we can style the div as one unit -- we can add a margin, border, padding, whatever. </p>
<p>It's like how by moving a bookshelf, we can move everything in it without dealing with each piece.</p>
<p>Note how we're writing the code too: everything in the div is indented, and the opening and closing div tags line up. Programmers keep their code structured because it helps them see the structure of the page -- you can imagine the boxes.</p>
</div>
</section>
<section>
<h2>With your mentor</h2>
<ul class="presentation-7">
<li>Think you understand how the box model works? Let's see if you're ready to be <a href="http://codewithme.us/exercises/box-model-ninja.html">A BOX MODEL NINJA!</a></li>
<li>Practice <a href="http://codewithme.us/portland/exercises.html#lesson-7">the box model</a> by trying out margin, padding, width, border and background-color in your practice file. </li>
<li><strong>Do exercise #7</strong>: <a href="http://codewithme.us/portland/exercises.html#exercise-7">Design it Twitter-style, part two</a>. </li>
</li>
<li>Work on your project.</li>
</ul>
</section>
</div>
<!-- The navigational controls UI -->
<aside class="controls">
<a class="left" href="#">◄</a>
<a class="right" href="#">►</a>
<a class="up" href="#">▲</a>
<a class="down" href="#">▼</a>
</aside>
<!-- Presentation progress bar -->
<div class="progress"><span></span></div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
transition: Reveal.getQueryHash().transition || 'linear', // default/cube/page/concave/linear(2d)
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/highlight.js', async: true, callback: function() { window.hljs.initHighlightingOnLoad(); } },
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'lib/js/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'lib/js/data-markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'socket.io/socket.io.js', async: true, condition: function() { return window.location.host === 'localhost:1947'; } },
{ src: 'plugin/speakernotes/client.js', async: true, condition: function() { return window.location.host === 'localhost:1947'; } },
]
});
</script>
</body>
</html>