Skip to content

Commit e7e01e9

Browse files
Revised positioning exercise, added presenter notes.
1 parent 92619eb commit e7e01e9

3 files changed

Lines changed: 61 additions & 35 deletions

File tree

index.html

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,11 +1473,14 @@ <h2>Position: relative</h2>
14731473
<section class="slide">
14741474
<h2>Position: absolute</h2>
14751475

1476-
<p>When positioning an element as <code>absolute</code>, it needs to also be paired with <code>relative</code> positioning. <code>relative</code> on it's own doesn't affect other elements but it is used to <em>contain</em> an <code>absolute</code> position element to a particular spot. Otherwise, it will position itself to the <em>viewport</em>, or browser window.</p>
1476+
<p>When positioning an element as <code>absolute</code>, it can be tricky. It needs to also be paired with another positioning property, added to a parent element, to <em>contain</em> it to a particular spot.</p>
1477+
1478+
<p>Usually <code>relative</code> positioning is used because it doesn't affect other elements around it. However, the absolute values will be <em>relative</em> to the next parent element with relative, absolute or fixed positioning. If there is no such parent, it will default to the browser window.</p>
14771479
<pre><code>&lt;div class=&quot;container&quot;&gt;
14781480
&lt;div class=&quot;box&quot;&gt;&lt;/div&gt;
14791481
&lt;/div&gt;</code></pre>
1480-
1482+
1483+
Try removing <code>position: relative;</code> in the example below and see what happens.<br>
14811484
<textarea class="snippet" data-subject="#absolute">.container {
14821485
position: relative;
14831486
}
@@ -1486,20 +1489,23 @@ <h2>Position: absolute</h2>
14861489
height: 100px;
14871490
background: blue;
14881491
position: absolute;
1489-
top:;
1492+
top: 0;
14901493
}</textarea>
14911494

14921495
<div id="absolute">
14931496
<div class="container">
14941497
<div class="box"></div>
14951498
</div>
14961499
</div>
1500+
<div class="presenter-notes">
1501+
<p>Assure learners that this is a confusing concept and it will be demonstrated again in the upcoming exercise.</p>
1502+
</div>
14971503
</section>
14981504

14991505
<section class="slide">
15001506
<h2>Position: fixed</h2>
15011507

1502-
<p>When positioning an element as <code>fixed</code>, it will <em>always</em> be positioned to the viewport. <code>relative</code> won't have any effect on this property. Also, it will always stay fixed on the page, even on page scroll.</p>
1508+
<p>When positioning an element as <code>fixed</code>, it will <em>always</em> be positioned to the viewport. <code>relative</code> or <code>absolute</code> won't have any effect on this property. Also, it will always stay fixed on the page, even on page scroll.</p>
15031509
<pre><code>&lt;div class=&quot;container&quot;&gt;
15041510
&lt;div class=&quot;box&quot;&gt;&lt;/div&gt;
15051511
&lt;/div&gt;</code></pre>
@@ -1522,47 +1528,56 @@ <h2>Position: fixed</h2>
15221528
</div>
15231529
</section>
15241530

1525-
<section class="slide" data-markdown>
1526-
##Class Exercise - Positioning the Header & Nav
1527-
1528-
Position the nav to the top right of the header element.
1529-
1530-
header {
1531-
position: relative;
1532-
}
1533-
nav {
1534-
position: absolute;
1535-
right: 20px;
1536-
top: 20px;
1537-
}
1531+
<section class="slide">
1532+
<h2>Class Exercise - Positioning the Header &amp; Nav</h2>
15381533

1534+
<p>Set the <em>entire</em> header itself to a fixed position so it stays in place at the top of the page on scroll.</p>
15391535

1540-
The *entire* header itself should be set to fixed positioning so when you scroll the page, it stays fixed at the top.
1536+
<pre><code>header {
1537+
position: fixed;
1538+
}
1539+
</code></pre>
15411540

1542-
header {
1543-
position: fixed;
1544-
}
1541+
<p>Positioning takes the element out of the natural stacking order. See how the profile picture “jumped” underneath the header when <code>position: fixed</code> was applied? It’s because it doesn’t “see” that there’s an element before it, so it wants to slide up to the next available slot. Add some padding on the top of the <code>section</code> element to push the content down below the fixed header. Now try scrolling the page.</p>
15451542

1546-
Notice that adding this property changes the page. When you position an element, it automatically becomes the width of its content. Set the width to 100% so it becomes as wide as the browser.
1543+
<pre><code>section {
1544+
padding-top: 125px;
1545+
}
1546+
</code></pre>
15471547

1548-
Also, set the background to white so the content underneath doesn't show through when you scroll the page. Add a border on the bottom to create a separation of the header from the page content.
1548+
<p>Update the <code>header</code> css by setting the background to white so the content underneath doesnt show through when you scroll the page. Also, add a border on the bottom to create a separation of the header from the page content.</p>
15491549

1550+
<pre><code>header {
1551+
position: fixed;
1552+
background: white;
1553+
border-bottom: 1px solid #eee;
1554+
}
1555+
</code></pre>
15501556

1551-
header {
1552-
position: fixed;
1553-
width: 100%;
1554-
background: white;
1555-
border-bottom: 1px solid #eee;
1556-
}
1557+
<p>Why doesn’t the header go all the way across? When you position an element, it automatically becomes the width of its content. Set the width to 100% so it becomes as wide as the browser. </p>
15571558

1558-
Positioning takes the element out of the natural stacking order. See how the profile picture "jumped" underneath the header when position: fixed was applied? It's because it doesn't "see" that there's an element before it, so it wants to slide up to the next available slot. Add some padding on the top of the section element to push the content down below the fixed header.
1559+
<pre><code>header {
1560+
position: fixed;
1561+
background: white;
1562+
border-bottom: 1px solid #eee;
1563+
width: 100%;
1564+
}
1565+
</code></pre>
15591566

1560-
section {
1561-
padding-top: 125px;
1562-
}
1567+
<p>Next up, position the nav to the top right of the header element. Since the header already has positioning applied to it, the nav will be relative to it.</p>
15631568

1569+
<pre><code>nav {
1570+
position: absolute;
1571+
right: 20px;
1572+
top: 20px;
1573+
}
1574+
</code></pre>
15641575

1565-
Your page should look like [example 6](project/examples/exercise6-about.html). Note how the header looks the same on all three pages now... except the home page! Where did the navigation disappear off to?
1576+
<p>Your page should look like <a href="project/examples/exercise6-about.html">example 6</a>. Note how the header looks the same on all three pages now… except the home page! Where did the navigation disappear off to?</p>
1577+
1578+
<div class="presenter-notes">
1579+
<p>Reinforce the ordering of CSS styles for organization during this exercise and stress the importance of keeping the styles in related groupings to keep from possibly duplicating styles or creating specificity issues.</p>
1580+
</div>
15661581
</section>
15671582

15681583
<section class="slide" data-markdown>

project/examples/css/exercise6.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ nav ul li {
8383
}
8484
nav a {
8585
padding: 5px 15px;
86+
display: block;
8687
text-transform: uppercase;
8788
}
8889

@@ -93,6 +94,11 @@ nav a {
9394
width: 50%;
9495
margin-right: 20px;
9596
}
97+
.quote {
98+
clear: both;
99+
text-align: center;
100+
padding-top: 20px;
101+
}
96102

97103

98104
/* FOOTER

project/examples/exercise6-about.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ <h2>Hello!</h2>
2727

2828
<p>[Personal summary or life story here] Lorem ipsum dolor sit amet, consectetur adipisicing elit. Debitis laboriosam officia blanditiis tempora sit fugiat molestiae iusto impedit ipsa cum, asperiores laborum, esse, doloribus explicabo! Autem, distinctio provident itaque non.</p>
2929
<p>Links to stuff about you, if needed. <a href="#">Link example</a> and <a href="#">another link example</a>.</p>
30-
<p>Or another paragraph! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque maiores dolor id voluptatibus iure eum hic similique, cum impedit possimus nesciunt deleniti atque fugiat. Nesciunt in ipsum voluptatem debitis nihil!</p>
30+
<p>Or another paragraph! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque maiores dolor id voluptatibus iure eum hic similique, cum impedit possimus nesciunt deleniti atque fugiat. Nesciunt in ipsum voluptatem debitis nihil!</p>
31+
32+
<blockquote class="quote">
33+
<p>The more that you read, the more things you will know. The more that you learn, the more places you'll go.</p>
34+
<cite>― Dr. Seuss, I Can Read With My Eyes Shut!</cite>
35+
</blockquote>
3136
</section>
3237

3338
<footer>

0 commit comments

Comments
 (0)