Chapter 2 - Part 3 (1)
Chapter 2 - Part 3 (1)
(CoSc3121)
Chapter 2 (Part III)
Web Page Development Using HTML
body{
font-family: arial, sans-serif;
font-size: 100%; }
• rel: Tells the browser what to expect (specifies the relationship between the current document and
the linked document)
• stylesheet
• alternate
• type: Tells the browser the type of document linked. Common values:
• text/css
• text/javascript
/* An external stylesheet */
a { text-decoration: none }
a:hover { text-decoration: underline; color: red;
background-color: #ccffcc;
}
li em { color: red; font-weight: bold;
background-color: #ffffff;
}
ul { margin-left: 2cm; }
ul ul { text-decoration: underline; margin-left: .5cm; }
20
<!-- Linking external style sheets -->
<html >
<head>
<title>Linking External Style Sheets</title>
<link rel = "stylesheet" type = "text/css"
href = "styles.css" />
</head>
<body>
<h1>Shopping list for <em>Monday</em>:</h1>
<ul>
<li>Milk</li>
<li>Bread
21
<ul>
<li>White bread</li>
<li>Rye bread</li>
<li>Whole wheat bread</li>
</ul>
</li>
<li>Rice</li>
<li>Potatoes</li>
<li>Pizza <em>with mushrooms</em></li>
</ul>
<p>
<a href = "http://www.food.com">Go to the Grocery store</a>
</p>
</body>
</html>
22
Cascading Style Sheets (cont...)
The CSS Box Model
• All HTML elements can be considered as boxes. In CSS, the term
"box model" is used when talking about design and layout.
• The CSS box model is essentially a box that wraps around HTML
elements, and it consists of: margins, borders, padding, and the
actual content.
• The box model allows us to place a border around elements and to
define space between elements.
Cascading Style Sheets (cont...)
The CSS Box Model (cont...)
• The image below illustrates the box model:
Cascading Style Sheets (cont...)
The CSS Box Model (cont...)
• Margin - Clears an area around the border. The margin does not have a
background color, it is completely transparent
• Border - A border that goes around the padding and content. The border is
affected by the background color of the box
• Padding - Clears an area around the content. The padding is affected by the
background color of the box
• Content - The content of the box, where text and images appear
(NB. In order to set the width and height of an element correctly in all browsers,
you need to know how the box model works.)
Cascading Style Sheets (cont...)
The CSS Box Model (cont...)
• NB: when you specify the width and height properties of an element
with CSS, you are just setting the width and height of the content
area. To know the full size of the element, you must also add
the padding, border and margin.
• The total width of the element in the example below is 300
___px:
width:250px;
padding:10px;
border:5px solid gray;
margin:10px;
Cascading Style Sheets (cont...)
The CSS Box Model (cont...)
• Let's do the math:
250px (width)
+ 20px (left and right padding)
+ 10px (left and right border)
+ 20px (left and right margin)
= 300px
Cascading Style Sheets (cont...)
The CSS Box Model (cont...)
• The total width of an element should always be calculated like this:
• Total element width = width + left padding + right padding + left border +
right border + left margin + right margin
33
<body>
<p class="none">No border.</p>
<p class="dotted">A dotted border.</p>
<p class="dashed">A dashed border.</p>
<p class="solid">A solid border.</p>
<p class="double">A double border.</p>
<p class="groove">A groove border.</p>
<p class="ridge">A ridge border.</p>
<p class="inset">An inset border.</p>
<p class="outset">An outset border.</p>
<p class="hidden">A hidden border.</p>
</body>
</html>
34
35
Cascading Style Sheets (cont...)
CSS Border Properties (cont...)
• Border-Width
• The border-width property is used to set the width of the border.
• The width is set in pixels, or by using one of the three pre-defined values: thin,
medium, or thick.
• Note: The "border-width" property does not work if it is used alone.
Use the "border-style" property to set the borders first.
p.one{
border-style:solid;
border-width:5px;
}
p.two{
border-style:solid;
border-width:medium;
}
Cascading Style Sheets (cont...)
• Imagine that you only had 250px of space. Let's make an element
with a total width of 250px:
• Example:
width: 220px;
padding: 10px;
border: 5px solid gray;
margin: 0px;
Reading Assignment
• Read about the following Html5 elements and include them in your
project implementation.
• <aside> • <main>
• <details> • <mark>
• <figcaption> • <nav>
• <figure> • <section>
• <footer> • <summary>
• <header> • <time>
• <video> • <article>
• <audio>
END