Lab 07
Lab 07
Approximate Time
The exercises in this lab should take approximately 75 minutes to complete.
Textbook by Pearson
http://www.funwebdev.com
CREATING TABLES
PREPARING DIRECTORIES
1 If you haven’t done so already, create a folder in your personal drive for all the labs for
this book.
2 From the main labs folder (either downloaded from the textbook’s web site using the
code provided with the textbook or in a common location provided by your instructor),
copy the folder titled lab07 to your course folder created in step one.
POSITIONING
Exercise 7.2 — RELATIVE POSITIONING
A moved element via absolute position is actually positioned relative to its nearest
positioned ancestor container (that is, a block-level element whose position is fixed,
relative, or absolute). In this example, the <figcaption> is absolutely positioned; it is
moved 150 px down and 200 px to the left of its nearest positioned ancestor, which
happens to be its parent (the <figure> element).
figcaption {
font-size: 1.25em;
background-color: yellow;
padding: 5px;
top: 90px;
left: 140px;
position: absolute;
}
Notice that the caption now overlaps both the underlying paragraph text and the figure
image.
3 Modify the following styles (some CSS omitted here for clarity) and test.
figure {
...
position: absolute;
z-index: 5;
}
figcaption {
...
position: absolute;
z-index: 1;
}
Note that this did not move the <figure> on top of the <figcaption> as one might
expect. This is due to the nesting of the caption within the figure.
figcaption {
...
position: absolute;
z-index: -1;
}
The <figure> zindex could be any value equal to or above 0 as long as the <figcaption>
is below 0.
figcaption {
...
position: absolute;
z-index: 1;
}
If the <figure> zindex is given a value less than 0, then any of its positioned
descendants change as well. Thus both the <figure> and <figcaption> move
underneath the body text.
FLOATING
Exercise 7.5 — FLOATING ELEMENTS
4 Modify the <p> element after the figures as follows and test:
<p class="first">When, while the lovely valley ...
padding: 5px;
position: absolute;
top: 130px;
left: 10px;
}
Since absolute positioning is positioning in relation to the closest positioned ancestor,
we will also need to position the <figure>.
LAYOUTS
The exercises so far in this lab showed two different ways to move items
out of the normal top-down flow, namely, by using positioning and by
using floats. They are the raw techniques that you can use to create
more complex layouts.
background-color: #A9A9A9;
padding: 0.5em;
width: 10em;
float: left;
}
aside {
color: white;
background-color: #D3C6BA;
padding: 0.5em;
width: 10em;
position: absolute;
right: 0;
top: 0;
}
Can you figure out what is wrong (and the solution)? Remember that absolute
positioning is relative to the last positioned element. There is no positioned element, so
RESPONSIVE DESIGN
Exercise 7.12 — MEDIA QUERIES
<title>Chapter 7</title>
<link rel="stylesheet" href="lab07-exercise12-mobile.css"
media="screen and (max-width:480px)" />
<link rel="stylesheet" href="lab07-exercise12-desktop.css"
media="screen and (min-width:481px)" />
</head>
We are adding an additional style sheet for mobile browser sizes.
4 Edit lab07-exercise12-mobile.css (this is the mobile style sheet) as follows and test.
main {
width: 100%;
margin-left: auto;
margin-right: auto;
}
nav {
color: white;
background-color: #A9A9A9;
padding: 0.5em;
width: 100%;
/* be sure to delete the float as well */
}
div#main {
padding: 0.5em;
margin-left: 0;
}
Fundamentals of Web Development 13
figure img {
max-width: 100%;
}
Notice that when the browser window shrinks to mobile size, the two-column layout is
replaced with a single column. This requires removing the floats and the margins.
CSS3 FEATURES
Exercise 7.14 — TRANSFORMS
prefix was necessary for Chrome browsers. You should test with and without this extra
prefix and see if it works now without it. If so, then you can remove the additional prefix
line in the following steps.
}
.combo-2 {
filter: brightness(1.3) contrast(1.1) hue-rotate(180deg) saturate(2);
-webkit-filter: brightness(1.3) contrast(1.1) hue-rotate(180deg)
saturate(2);
}
This example shows that you can combine multiple filters in once property setting.
animation-name: animOne;
animation-duration: 1.5s;
}
This tells the browser to use the animation named animOne and have it run across 1.5
seconds. We still need to define this animation.
}
}
This specifies a start state and an end state. This animation varies four things: the
opacity, the size, the rotation, and the left margin.
6 Comment out the animation styles entered in steps 2 and 4 and replace them with the
following style and test:
animation: animTwo 5s ease-out 1s 3;
This uses the shortcut property that allows you to combine the different animation
properties into a single line.
Fundamentals of Web Development 19
GRID SYSTEMS
Exercise 7.19 — USING BOOTSTRAP
</ul>
</nav>
<div class="row">
...
Bootstrap also comes with many additional classes that can simplify the process of
quickly creating a design. For more information, see http://getbootstrap.com/.
4 Modify the first column by adding a panel and list using some of Bootstrap’s built-on
formatting classes. Test.
<div class="row">
<div class="col-md-3">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Destinations</h3>
</div>
<div class="panel-body">
<ul class="list-group">
<li class="list-group-item">Austria</li>
<li class="list-group-item">Canada</li>
<li class="list-group-item">France</li>
<li class="list-group-item">Italy</li>
<li class="list-group-item">Spain</li>
</ul>
</div>
</div>
</div>
...
5 Modify the second column by making use of an additional Bootstrap class and test.
<div class="col-md-9">
<div class="jumbotron">
<h1>Main Content</h1>
<p>
CSS frameworks provide similar grid features. Bootstrap and
Material Lite both use a 12-column grid. The grid is constructed using div
elements with classes defined by the framework.
</p>
</div>
</div>
6 Add to the second column by adding a nested row after the jumbotron and test.
<h2>Nested columns</h2>
<div class="row">
<div class="col-md-3">
<img src="images/464.jpg" alt="London">
<h5>London</h5>
<button type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-info-sign"
aria-hidden="true"></span> View
<button>
<button type="button" class="btn btn-success">
<span class="glyphicon glyphicon-shopping-cart"
aria-hidden="true"></span> Cart
</button>
</div>
<div class="col-md-3">
Fundamentals of Web Development 21