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 setting the position to <code>relative</code>, elements will still appear within the <strong>normal flow</strong> a page but will unlock the additional offset properties (top, right, bottom, left). You can use these values to nudge the element in different directions. Try adding a top value (or any offset property).</p>
<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>
50
+
51
+
<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>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>
Copy file name to clipboardExpand all lines: framework/extras-sticky-footer.html
+9Lines changed: 9 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,15 @@
27
27
28
28
<main>
29
29
<sectionclass="slide" data-markdown>
30
+
##Sticky Footer
31
+
32
+
Remember the natural stacking order? HTML elements stack on top of each other in the order that they appear in the HTML. Each element is as tall as their content (unless otherwise specified).
33
+
34
+
On the home page, the footer appears right below the headings. On the about page, it appears on the bottom because the content is long enough to scroll.
35
+
36
+
To ensure that your footer is always at the bottom of the page, no matter how long the page content is or how big the browser window is, use a "sticky footer".
37
+
</section>
38
+
<sectionclass="slide" data-markdown>
30
39
##Create a Sticky Footer
31
40
32
41
We'll be following these instructions: http://css-tricks.com/snippets/css/sticky-footer/
Sometimes floats and display just doesn't cut it for laying out page elements.
1420
1420
1421
1421
The `position` property can be used to place elements in specific spots on the page without affecting the elements around it the way floats do. There are three options: `relative`, `absolute` and `fixed`. Elements are all `static` by default.
1422
1422
1423
1423
`position` is used in conjunction with **offset properties**: `top`, `right`, `bottom`, and `left`. These are use to identify where an element will be positioned.
1424
-
</section>
1425
-
<sectionclass="slide">
1426
-
<h2>Position: relative</h2>
1427
-
1428
-
<p>When setting the position to <code>relative</code>, elements will still appear within the <strong>normal flow</strong> a page but will unlock the additional offset properties (top, right, bottom, left). You can use these values to nudge the element in different directions. Try adding a top value (or any offset property).</p>
<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>
1446
-
1447
-
<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>
1471
-
</div>
1425
+
To view more about positioning, check out this extra resource: [position relative, absolute & fixed](framework/extras-positioning.html).
1472
1426
</section>
1473
1427
1474
1428
<sectionclass="slide">
1475
-
<h2>Position: fixed</h2>
1476
-
1477
-
<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>
<h2>Class Exercise - Positioning the Header & Nav</h2>
1502
-
1503
-
<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>
1431
+
<p>Set the <em>entire</em> header to a fixed position so it stays in place at the top of the page on scroll.</p>
1504
1432
1505
1433
<pre><code>header {
1506
1434
position: fixed;
1435
+
top: 0;
1507
1436
}
1508
1437
</code></pre>
1509
1438
1510
1439
<p>Let's check these changes on our <strong>About</strong> page.</p>
1511
-
<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. Then try scrolling down the page.</p>
1440
+
<p>Positioning also 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.</p>
1441
+
<p>Add some padding on the top of the <code>section</code> element to push the content down below the fixed header. Then try scrolling down the page.</p>
1512
1442
1513
1443
<pre><code>section {
1514
1444
padding-top: 125px;
@@ -1534,7 +1464,7 @@ <h2>Class Exercise - Positioning the Header & Nav</h2>
1534
1464
}
1535
1465
</code></pre>
1536
1466
1537
-
<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>
1467
+
<p>Next up, position the <code>nav</code> 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>
1538
1468
1539
1469
<pre><code>nav {
1540
1470
position: absolute;
@@ -1543,28 +1473,31 @@ <h2>Class Exercise - Positioning the Header & Nav</h2>
1543
1473
}
1544
1474
</code></pre>
1545
1475
1546
-
<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>
1476
+
<p>Your page should look like <ahref="project/examples/exercise7-about.html">example 7</a>. Note how the header looks the same on all three pages now.</p>
1477
+
<p>Wait! Where did the footer content disappear off to on the home and contact pages!?</p>
1547
1478
1548
1479
<divclass="presenter-notes">
1549
1480
<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>
1550
1481
</div>
1551
1482
</section>
1552
1483
1553
1484
<sectionclass="slide" data-markdown>
1554
-
##Class attribute & the Home page styles
1485
+
##Home page styles
1486
+
1487
+
The home page and contact page currently doesn't have any content in it so the footer is just "underneath" the header.
1555
1488
1556
-
The final design for the home page is different from the other two pages including the order of the HTML. On **index.html**, the nav HTML comes *before* the header. The nav didn't disappear, it's just *under* the header.
1489
+
However, the final design for the home page is different from the other two pages so we'll need to create special styles for the home page.
1557
1490
1558
-
For the Home page, we can add a `class` attribute to create a specific selector to override the styles that are shared between the About and Contact page. This class will allow us to apply specific styles just for the home page.
1491
+
Let's use the `class` attribute to create a selector to allow us to apply specific styles just to the home page.
1559
1492
1560
-
Let's add a class to the `body` tag so we can override any styles for any element contained within the page.
1493
+
Add the class to the `body` tag so we can override any styles for any element contained within the entire page.
1561
1494
1562
1495
```
1563
1496
<body class="home">
1564
1497
```
1565
1498
</section>
1566
1499
<sectionclass="slide" data-markdown>
1567
-
##Class Exercise #7 - Homepage Header & Nav
1500
+
##Class Exercise #8 - Homepage Header & Nav
1568
1501
1569
1502
These are the styles we are going to change to update the home page.
1570
1503
@@ -1596,27 +1529,13 @@ <h2>Class Exercise - Positioning the Header & Nav</h2>
1596
1529
}
1597
1530
```
1598
1531
1599
-
Add the `.highlight` class to your first name again, to match the styles on the other pages.
1532
+
If you haven't already, add the `.highlight` class to your first name, to match the styles on the other pages.
Your page should now look something like [example 7](project/examples/exercise7-home.html), located in your examples folder.
1606
-
</section>
1607
-
1608
-
<sectionclass="slide" data-markdown>
1609
-
##Sticky Footer
1610
-
1611
-
Remember the natural stacking order? HTML elements stack on top of each other in the order that they appear in the HTML. Each element is as tall as their content (unless otherwise specified).
1612
-
1613
-
On the home page, the footer appears right below the headings. On the about page, it appears on the bottom because the content is long enough to scroll. And on the contact page, you can't even see it because it's hidden underneath the positioned header!
1614
-
1615
-
To ensure that your footer is always at the bottom of the page, no matter how long the page content is or how big the browser window is, use a "sticky footer".
1616
-
1617
-
For "homework", [follow these instructions](framework/extras-sticky-footer.html) to create a sticky footer.
1618
-
1619
-
Let's finish the day with background images and forms!
1538
+
Your page should now look something like [exercise8-home](project/examples/exercise8-home.html), located in your examples folder.
Though we've covered a lot of material today, there are still lots of things to add to give your web page that extra personalization, finalize some styles and add some polish.
0 commit comments