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
<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>
<p>Assure learners that this is a confusing concept and it will be demonstrated again in the upcoming exercise.</p>
1502
+
</div>
1497
1503
</section>
1498
1504
1499
1505
<sectionclass="slide">
1500
1506
<h2>Position: fixed</h2>
1501
1507
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>
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
+
<sectionclass="slide">
1532
+
<h2>Class Exercise - Positioning the Header & Nav</h2>
1538
1533
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>
1539
1535
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>
1541
1540
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>
1545
1542
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>
1547
1547
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 doesn’t 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>
1549
1549
1550
+
<pre><code>header {
1551
+
position: fixed;
1552
+
background: white;
1553
+
border-bottom: 1px solid #eee;
1554
+
}
1555
+
</code></pre>
1550
1556
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>
1557
1558
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>
1559
1566
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>
1563
1568
1569
+
<pre><code>nav {
1570
+
position: absolute;
1571
+
right: 20px;
1572
+
top: 20px;
1573
+
}
1574
+
</code></pre>
1564
1575
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 <ahref="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
+
<divclass="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>
Copy file name to clipboardExpand all lines: project/examples/exercise6-about.html
+6-1Lines changed: 6 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,12 @@ <h2>Hello!</h2>
27
27
28
28
<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>
29
29
<p>Links to stuff about you, if needed. <ahref="#">Link example</a> and <ahref="#">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
+
<blockquoteclass="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>
0 commit comments