week5-Ch6
week5-Ch6
Dear Students:
In order to study for the midterm assessment, I recommend that you complete the review
questions at the end of each chapter. Answers to these are available in the back of the book
online. If you go to the website for the textbook, each chapter also has study guides
available and learning tools such as flashcards.
You will have up to 2 hours (120 minutes) to take the exam. It is worth up to 100 points.
Answer each of the questions to the best of your ability by typing the answer in the box
provided or by selecting the best choice in the drop down or option offered, leaving nothing
blank (no credit can be given unless something is entered).
There are 45 questions on the exam. There are 35 multiple choice questions worth 2 points
each and 10 essay/short answer questions worth up to 3 points each. Once you click Next
Page to go to the next question, you will not be able to go backwards to review or make
changes to previous questions.
Professor Crawford
2
Web Development & Design
Foundations with HTML5
CHAPTER 6
PAGE LAYOUT
4
Copyright © Terry Felke-Morris http://terrymorris.net
Content
◦ Text & web page elements The Box Model
in the container
Padding
◦ Area between the content
and the border
Border
◦ Between the padding
and the margin
Margin
◦ Determines the empty
space between the element
and adjacent elements
5
Copyright © Terry Felke-Morris http://terrymorris.net
Configure Margin with CSS
◦ The margin property
◦ Related properties:
◦ margin-top, margin-right, margin-left, margin-bottom
◦ Configures empty space between the element and adjacent
elements
◦ Syntax examples
h1 { margin: 0; }
h1 { margin: 20px 10px; }
h1 { margin: 10px 30px 20px; }
h1 { margin: 20px 30px 0 30px; } Demo
◦ Syntax examples
h1 { padding: 0; }
h1 { padding : 20px 10px; }
h1 { padding : 10px 30px 20px; }
h1 { padding : 20px 30px 0 30px; }
Copyright © Terry Felke-Morris http://terrymorris.net
Box model in Action
Demo
clear: left;
was applied to the h2.
Now the h2 text
displays AFTER the
floated image.
Demo
overflow: auto;
was applied to the div
that contains the image
and paragraph.
Now the background
extends and the h2 text
displays AFTER the
Copyright © Terry Felke-Morris http://terrymorris.net
floated image.
CSS display Property
Configures how and if an element is displayed
◦ display: none;
◦ The element will not be displayed.
◦ display: block;
◦ The element is rendered as a block element – even if it is actually an
inline element, such as a hyperlink.
◦ display: inline;
◦ The element will be rendered as an inline element – even if it is
actually a block element – such as a <li>.
o display: inline-block;
o The element will display as an inline display element adjacent to other
inline display elements but also can be configured with properties of
block display elements including width and height.
Demo
13
Copyright © Terry Felke-Morris http://terrymorris.net
Page Layout
Single Column -> Two Column
Single Column Two Column
Wireframe Wireframe
<body>
<div id="wrapper">
<header> <header>
<nav> </nav>
<main> </main>
<footer> </footer>
</div>
</body>
Demo
Demo Demo
26
Copyright © Terry Felke-Morris http://terrymorris.net
HTML5 Structural Elements REVIEW
Header Element
◦ block display; contains the headings of either a web page document or an
area in the document such as a section or article
Nav Element
◦ block display; contains a section
of navigation hyperlinks
Main Element
◦ block display; contains main page content
Footer Element
◦ block display; contains the footer
content of a web page or specific
area (such as a section or article) on a web page
Configure an id:
◦ If the style is specific to only one element on a page
◦ Use the # notation in the style sheet.
◦ Use the id attribute in the HTML.
29
Copyright © Terry Felke-Morris http://terrymorris.net
Choosing a Name for a class or an id
A class or id name should be descriptive of the
purpose:
◦ such as nav, news, footer, etc.
Source: http://code.google.com/webstats
30
Copyright © Terry Felke-Morris http://terrymorris.net
• To place an element at a specific position on
a page use:
31
Absolute Positioning
Enables you to place an element at specific coordinates
Takes element out of normal flow of document
Any subsequent content flows into space previously
occupied by element
32
Move an element relative to its default position on the
page, where browser would have place the element if style
was not applied to it
position: relative;
33
Fix an element in a precise spot in document window
so that while rest of page scrolls, it does not
position: fixed;
34
Default – No Positioning Added Example
Now that we've basically gone over the above definitions, let's do an actual example, so that we can see for
ourselves how this works.
The best way to show this is to create 2 elements, 2 <div> tag elements. By viewing 2 <div> tags, in relation to each
other, we can see how absolute, relative, and fixed positioning works, from a visual point of view, which is most
likely the best way to learn this.
position:absolute;
The full CSS code for the div tags will now be:
#outer { When one div tag is nested in
width:300px; another and the inner div tag is
height:300px; absolute positioned, it's no longer
relative according to the outer div
background:#777; element. It's absolute positioned
margin:50px; now according to the entire page.
} So, as in the example above, where
we add the line top:10px, the inner
#inner { div element, even though nested
width:100px; inside the outer div tag, will now be
height:100px; 10px from the top of the page. This
means it's no longer contained
background:#999; within the outer div element but is
position: absolute; absolute positioned to the page. This You can see that the inner lighter gray area is the
top:10px; inner div. And the larger, darker gray area is the
only happens when the inner div outer div.
} element is absolute positioned and
the outer div is not. This is how the 2 elements look when one is nested
inside the other
with the outer element having no positioning and
the inner element being absolute positioned
with a 10px margin from the top.
36
Outer Div Has Relative Positioning and Inner Div Has
Absolute Positioning
Now let's go to the case where the outer div has relative positioning and the inner div has absolute positioning.
This is now more the desired effect that you're probably looking for.
When we declare the outer div tag to have relative positioning and the
inner div tag to have absolute positioning, we're saying that the inner tag
has absolute positioning relative, not to the page, but to the outer div tag.
Since the outer div element is declared to be relative, it functions as a
relative element to the inner. Thus, the inner tag does not function
absolute to the page but to the outer div element.
The full CSS code for the div tags will now be:
#outer {
width:300px;
height:300px;
background:#777;
margin:50px;
position: relative;
} You can see that the inner lighter gray area is the
inner div. And the larger, darker gray area is the
outer div.
#inner {
width:100px; This is how the 2 elements look when one is nested
height:100px; inside the other with the outer element having
relative positioning and the inner element being
background:#999; absolute positioned with a 10px margin from the
position: absolute; top.
top:10px;
} 37
Both Inner and Outer Div Elements Have Absolute
Positioning
When both inner and outer div elements have absolute positioning, they produce an effect that is similar to the
previous slide (with the outer div having relative positioning and the inner
div having absolute positioning). They both are in the same place on the
page and have the inner div with a 10px margin from the top of the outer
div. However, there is one key difference. With the outer div having
absolute positioning, it is fixed on the page at that position. Being that it is
not relative and it's absolute, it will stay permanently at that position. If
there is any text on the page or any element on the page at that position,
it will block or overshadow the text.
The full CSS code for the div tags will now be:
#outer {
width:300px;
height:300px;
background:#777;
margin:50px;
position: absolute; You can see that the inner lighter gray area is the
} inner div. And the larger, darker gray area is the
outer div.
To make the div element fixed (both outer and inner div elements), all you have to do is set the outer div element to
a fixed position.
#inner {
width:100px;
height:100px;
background:#999;
position: absolute; With this code, if you scroll down the page, you
top:10px; will see that the div elements always are
} displayed, even if you scroll down the page.
They are fixed and are always shown.
One trick to add so that you can scroll down the page and
see that is element is really fixed is to length your body
tag, by adding the following code:
body {
height:2000px;
}
39
• Specify stacking order with:
z-index: value z-index: 1
z-index: 3
z-index: 2
40
• Two different styles that allow you to hide
elements:
– Display style
– Visibility style
41
<!DOCTYPE html>
<html>
<head>
<style>
h1.visible {visibility: visible}
h1.hidden {visibility: hidden}
</style>
</head>
<body>
<h1 class="visible">This is a visible heading</h1>
<h1 class="hidden">This is an invisible heading</h1>
<p>Notice that the invisible heading still takes up space.</p>
</body>
</html>
42
NO CSS
(commented out)
43
44
With CSS … next
page
45
46
47