Practice - Exercise - 2 - Chap 4
Practice - Exercise - 2 - Chap 4
Practice Exercise 2
(Total Marks: 100%, 3%)
Part#1
In this exercise, you will use your text editor to create external, embedded, and inline styles for the
Durango Jewelry and Gem Shop home page. You will style the sections of the semantic wireframe
( header, nav, main, and footer ) and a div element that surrounds all of the content to center
the content on the page. You will also float an image to the left so that some of the content can fill the
empty space to the right of the image. Finally, you will clear the float and add margins and borders to
give your page a professional touch. The completed home page is shown in Figure 4–44. You will also
use professional web development practices to indent, space, comment, and validate your code.
Figure 4–44
Front End Web Development I CSD 1103
1. Open your text editor, and then open the apply04.html file from the Data Files for Students.
Use the File Save As feature to save the webpage in the chapter04\apply folder with the name
index04.html to create the home page.
2. Modify the comment at the top of the index.html page to include your name and today’s
date.
3. Start a new file in your text editor, and save it in the chapter04\apply folder with the name
styles04.css to create a style sheet.
4. Enter a CSS comment as the first line of the external style sheet with your name and
today’s your name and today’s your date. Recall that CSS comments are entered within /* and
*/ characters.
5. Style the body element with a uniform black text color and light-green background color:
6. In the head section of the index04.html file, enter an element to connect the page to the
external style sheet:
Save your changes. Open or refresh index04.html in a browser to make sure that the style
sheet is correctly connected to the HTML file.
7. Your next task is to center the content on the webpage. To do this, add <div> tags to
surround the content in the wireframe, and then apply a style to center the content within the
<div> tags as follows:
a. In index04.html, insert the <div id="outerwrapper"> opening tag just after the opening
<body> tag.
b. In index04.html, insert the </div> <!--close the outerwrapper--> closing tag and
comment just before the closing </body> tag.
outerwrapper:
#outerwrapper { width: 80%;
margin: 0 auto 0 auto;
}
d. Save your changes to both files, and then open or refresh index04.html in a browser to
make sure that the content is centered within 80% of the browser window.
8. Apply common sans-serif fonts to the header, nav, and footer sections, and common serif
fonts to the div id="main" section by adding the following style to the external stylesheet:
(Hint (Hint ( : After each step, save index04.html and styles04.css and then refresh
index04.html in the browser to make sure that each style is applied successfully.)
9. Style the text in the footer section to be 0.75em and centered by adding the following styles
to the external stylesheet:
10. Style the content within the div id="main" section to have a lighter background and 10px
of padding on all four sides by adding the following declarations to the existing #main
selector:
background-color: #F0F9E6;
padding: 10px;
11. Float the image to the left with the following style so that the existing Float the image to
the left with the following style so that the existing h1 and h2 content moves to the right of the
image:
12. Clear the float for the nav section with the following style:
13. Add a margin to the left of the h1 and h2 content in the nav section to insert white space
between the headings and the image. Given you want to apply the same rule to two specific
headings (but not other h1 and h2 content on the website), you will first give the tags the
same class attribute value and then apply the style to that class as follows:
b. In styles04.css, insert the following style to increase the size of the right margin for content
tagged with class="addrightmargin"
14. In index04.html, insert an embedded style sheet just below the link tag in the head section
to apply a rounded border to the div id="main" section:
<style>
#main { border-radius: 2em; }
</style>
15. In index04.html, insert <span> and </span> tags around “Smoky quartz” and “Soulmate
Crystal” in the first list item in the unordered list in the div id="main" section. Use the
style attribute to give each opening <span> tag an inline style that bolds the font of the
content within the <span> tags as follows:
16. Validate your HTML document using the W3C validator at validator.w3.org and fix any
errors that are identified. Validation is complete when the validator returns the message “This
document was successfully checked as HTML5!” in a green bar near the top of the webpage.
17. Add indents, spaces, and extra lines to your external style sheet to make it as professional
and easy to read as possible. Employ these conventions:
• Put the selector and opening brace on the first line. Alternatively, put the selector,
opening brace, and first declaration on the first line.
• Make sure that each property is separated from its value with a colon (:)
• Make sure that there are no spaces in values such as 10px or 20%.
• For each set of styles, position the closing brace on its own line
18. Validate your CSS file using the W3C validator at http://jigsaw.w3.org/css-validator/ and
fix any errors that are identified. Validation is complete with the validator returns the message
“Congratulations! No Error Found.”
19. Submit the index04.html and styles04.css files in a format specified by your instructor.
Your instructor may also ask you to submit the wirewrap01.jpg file used with index04.html.
Part#2
Figure 4-47
1. Open cityfarmer04.html in your HTML editor from the Data Files for Students and then
modify the comment at the top of the page to include your name and today’s date. Make sure
the <title>…</title> tags contain the text City Farmer Home Page.
2. Start a new file in your text editor, and save it in the lab1\styles folder with the name
farmerstyles04.css
3. Enter a CSS comment as the first line of the external style sheet with your name and
today’s your name and today’s your date. Recall that CSS comments are entered within /*
and */ characters.
4. Enter a style to apply a uniform black text color, a uniform serif font, and light-blue
background color to the body:
5. In the head section of the cityfarmer04.html file, enter an element to connect the page to
the external style sheet:
Save your changes, and then open or refresh cityfarmer04.html in a browser to make sure that
the style sheet is correctly connected to the HTML file. Note that in this exercise, the style
sheet is saved in the styles folder, so that path needs to be included in the href value.
6. Center the content by adding <div> and </div> tags to surround the content in the
wireframe, and then applying styles to center the content within the <div> and </div> tags as
follows:
© 2020 LAMBTON COLLEGE IN TORONTO
Front End Web Development I CSD 1103
a. In cityfarmer04.html, insert the <div id="outerwrapper"> opening tag just after the
opening <body> tag.
b. In cityfarmer04.html, insert the </div> <!-- close the outerwrapper--> closing tag and
comment just before the closing </body> tag. Save your changes to cityfarmer04.html.
c. In farmerstyles04.css, insert the following style to constrain the outerwrapper to 70% of the
width of the screen and to center the content within the outerwrapper:
7. Style the text in the footer section to have a font size of 0.75em and appear centered by
adding the following styles to the external stylesheet:
(Hint : Save and refresh the cityfarmer04.html file in your browser after every step to observe
and study the impact of each style.)
8. Style the content within the div id="main" section to have a light-brown background and
10px of padding on the top by adding the following style:
9. Float the image in the header to the left with the following style so that the <h1>, <h2>, and
<nav> content moves to the right of the image:
10. Remove the bullets from the list items in the nav section by adding the following style:
ul { list-style-type: none;
11. Push the content away from the image by adding a right margin to the img selector with
the following declaration:
margin-right: 3%;
12. Clear the float so that the content for the div id="main" section starts on its own line by
adding a second style rule with a #main selector:
13. You decide to float the second image right instead of left. Right now, your float rule is
written using the img selector so all img content is affected. To change the float value for the
second image, complete the following:
a. Add a Add a class="floatleft" attribute value pair to the first <img> tag (the logo) in the
cityfarmer04.html file. (Hint cityfarmer04.html file. (Hint cityfarmer04.html file. ( : The order
© 2020 LAMBTON COLLEGE IN TORONTO
Front End Web Development I CSD 1103
of attribute value pairs in the opening html tag do not affect how the code works in the
browser, but typically the most important attributes are listed first so the class="floatleft"
attribute would often be listed second or third.)
b. Add a Add a class="floatright" attribute value pair to the second <img> tag (tomatoes
in pots) in the cityfarmer04.html file.
d. Just below the .floatleft style in the CSS file, add the following style to float the second
image to the right:
14. To make sure the footer also starts on its own line, modify the selector for the rule that
clears all float to include both the #main and footer areas as follows:
17. Save and open the cityfarmer04.html page within a browser as shown in Figure 4–47.