Lab Activity 9 CSS Boxes and Horizontal Menu
Lab Activity 9 CSS Boxes and Horizontal Menu
PART 2: CSS
NAME :
MATRC NUMBER :
CLASS:
1
LAB ACTIVITY 9: CSS Boxes & Horizontal Menu
Duration: 2 Hours
Learning Outcomes
By the end of this laboratory session, you should be able to:
1. Control the dimensions of your boxes
2. Create borders around boxes
3. Set margins and padding for boxes
Activity 9A
Activity Outcome: Understanding the box model
Step 1: Open a HTML editor file and type the following. Save code as act9b.html
<!DOCTYPE html>
<html>
<head><title>CSS Box Model</title>
<style>
div {
background-color: lightgrey;
width: 300px;
border: 25px solid green;
padding: 25px;
margin: 25px;
}
</style></head>
<body>
<h2>Th Box Model</h2>
<p>The CSS box model is essentially a box that wraps around every
HTML element. </p>
<p>It consists of: borders, padding, margins, and the actual
content.</p>
28
Step 3: Answer the question. What is the differences between margin and padding?
Activity 9B(i)
Activity Outcome: Apply width and height
<!doctype html><html>
<head><title>CSS Box Width & Height</title>
<style>
div.box {
height: 300px;
width: 300px;
background-color: #ED0462;}
p { height: 75%;
width: 75%;
background-color: #0088dd;}
</style></head>
<body>
<div class="box">
<p>We can specify value for height and width using pixel or
percentage.</p>
</div>
</body></html>
Step 3: Answer the question. What is the actual height and widht in pixel of element <p>?
29
Activity 9C(i)
Activity Outcome: Apply Border Width, Style and Color
Notes : The CSS border properties allow you to specify the style, width, and color of an
element's border.
1. border-style property: set the style either dotted, dashed, solid and etc
2. border-width property:
set the width of the border.
The border-width property does not work if it is used alone. Use the
border-style property to set the border first.
3. border-color property: set color of the border
4. border-radius property: add rounded borders to an element
CSS border properties allows you to specify different style, color and width to side of border
( op border, right border, bottom border and left border)
If you want to specify different style, color and width to the border, you need to follow the order
which is : top – right – bottom – left.
Example A : Example B:
Output: Output:
Code: Code:
border-style: dotted; border-style: dotted dashed solid double;
border-top-style : dotted;
border-left- style : double
border-right- style: dashed
border-bottom- style : solid
30
Step 1: Open a HTML editor file and type the following. Save code as
act9C(i).html.
<!doctype html><html>
<head><title>Border Width</title>
<style>
p.one { border-style: solid;
border-width: 2px;
border-color: #0088dd;}
<body>
<p class="one"> Paragraph 1 </p>
<p class="two"> Paragraph 2 </p>
<p class="three"> Paragraph 3 </p>
<p class="four"> Paragraph 4 </p>
<p class="mix"> Paragraph 5 </p>
</body></html>
31
Activity 9C(ii)
Activity Outcome: Use Shorthand border property
Notes : As you can see from the activity 9c(i), there are many properties to consider when
dealing with borders.
To shorten the code, it is also possible to specify all the individual border properties in one
property.
The border property is a shorthand property for the following individual border properties:
border-width
border-style (required)
border-color
Step 1: Open a HTML editor file and type the following. Save code as act9C(ii).html.
<!doctype html><html>
<head><title>Shorthand Border</title>
<style>
p { width: 250px;
border: 3px dotted #0088dd;
}
</style></head>
<body>
<p> Shorthand Border </p>
</body></html>
32
Activity 9D
Activity Outcome: Apply Padding, Margin and Center
Step 1: Open a HTML editor file and type the following. Save code as act9d.html.
<!doctype html><html>
<head><title>Padding, Margin and Center</title>
<style>
p { width: 275px;
border: 2px solid #0088dd;}
33
Activity 9G
Activity Outcome: Apply different element of CSS boxes.
Step 1: Open a HTML editor file and type the following. Save code as act9g.html.
<!DOCTYPE html><html>
<head><title>Example Boxes</title>
<style>
</style></head>
<body>
<div id="page">
<div id="logo">
<img src="logo.gif" alt="The Analog" />
</div>
<ul id="navigation">
<li><a href="#">Home</a></li>
<li><a href="#">For Sale</a></li>
<li><a href="#">Repairs</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
<p>
<img src="keys.jpg" alt="Fender Rhodes"/>
</p>
<p>
We specialise in the sales and repair of classic keyboards, in
particular the Fender Rhodes and Hohner Clavinet.
</p>
</div>
</body></html>
34
Step 3: Add the following CSS code inside the <style> one by one and obeserve the output.
2. Write the CSS code for <div id=page> one by one and obeserve the output.
Center the box, by setting margin for left and right values to auto.
margin: 10px auto 10px auto;
3. Write the CSS code to create horizontal menu bar using the <ul> element
a. Create a box around <ul> element that has top and bottom border
ul { width: 570px;
border-top: 2px solid #000;
border-bottom: 1px solid #000;}
Center the box, by setting margin for left and right values to auto.
text-align: center;
35
b. Remove the bullets around the <li> element and disply them in single line
li { display: inline;}
The text for menus appear close to each other. Create a suitable margin around the li
element to add spaces between the text.
a { color: black; }
Add padding
** After you add the padding, the box cannot fit in the text. The contact menu appear in
new line. Modify the correct CSS properties so the all the menu will appear in single line
5. Add hover properties to the hyperlink. Move the cursor around the hyperlink to see the effect
of hover properties.
36