Cascading Style Sheets
Cascading Style Sheets
1. CSS BACKGROUNDS
property description
– Example
h1 {background-color: rgb(0,255,255);}
p {background-color:lightblue;}
div {background-color:#b0c4de;}
(b) background-image
• The background-image property specifies an
image to use as the background of an element.
• value consists of two tokens, each of which can be top, left, right,
bottom, center, a percentage, or a length value in px, pt, etc.
• value can be negative to shift left/up by a given amount
2. CSS TEXT FORMATTING
CSS Text Properties
text-decoration: (none, underline, line-through) -- p{text-decoration: underline;}
• Example
h1 {text-align: center;}
p.date {text-align: right;}
p.main {text-align: justify;}
(c) Text Decoration
• Example
– p.uppercase {text-transform: uppercase;}
– p.lowercase {text-transform: lowercase;}
– p.capitalize {text-transform: capitalize;}
3. CSS FONT PROPERTIES
property description
font-family which font will be used
• Example
– p.normal {font-style: normal;}
– p.italic {font-style: italic;}
– p.oblique {font-style: oblique;}
(c) CSS Font Size
• To avoid the resizing problem with Internet Explorer, many developers use em
instead of pixels.
• 1em is equal to the current font size. The default text size in browsers is 16px.
So, the default size of 1em is 16px.
• The size can be calculated from pixels to em using this formula: pixels/16=em
• Example
h1 {font-size:2.5em;} /* 40px/16=2.5em */
h2 {font-size:1.875em;} /* 30px/16=1.875em */
p {font-size:0.875em;} /* 14px/16=0.875em */
4. STYLING LINKS
• Links can be style with any CSS property (e.g. color, font-family, background-
color).
• Special for links are that they can be styled differently depending on what state they
are in.
• The four links states are:
– * a:link - a normal, unvisited link
– * a:visited - a link the user has visited
– * a:hover - a link when the user mouses over it
– * a:active - a link the moment it is clicked
• Example
a:link {color:#FF0000;} /* unvisited link */
a:visited {color:#00FF00;} /* visited link */
a:hover {color:#FF00FF;} /* mouse over link */
a:active {color:#0000FF;} /* selected link */
(a) Text Decoration
• Example
– a:link {text-decoration: none;}
– a:visited {text-decoration: none;}
– a:hover {text-decoration: underline;}
– a:active {text-decoration: underline;}
(b) Background Color
• Example
• a:link {background-color:#B2FF99;}
• a:visited {background-color:#FFFF85;}
• a:hover {background-color:#FF704D;}
• a:active {background-color:#FF704D;}
5. CSS LISTS
• Recall that in HTML, there are two types of
lists:
– UL - list items are marked with bullets
– OL- list items are marked with numbers or letters
Different List Item Markers
• Table Borders
– To specify table borders in CSS, use the border
property.
– The example below specifies a black border for
table, th, and td elements:
– Example
• table, th, td{border: 1px solid black;}
CSS TABLES (2)
• Example
– td{text-align: right;}
(c) Table Padding
• Example
– td{padding:15px;}
(d) Table Color
• Example
table, td, th{border:1px solid green;}
th{background-color: green; color: white;}
(7) CSS Box Model
• All HTML elements can be considered as boxes.
• To know the full size of the ELEMENT, you must also ADD the padding,
border and margin.
width:250px;
padding:10px;
border:5px solid gray;
margin:10px;
(b) CSS Border Width
• The border-color property is used to set the color of the border. The color
can be set by:
– * name - specify a color name, like "red"
– * RGB - specify a RGB value, like "rgb(255,0,0)"
– * Hex - specify a hex value, like "#ff0000“
• NB: The "border-color" property does not work if it is used alone. Use
the "border-style“ property to set the borders first.
• Example
– p.one{ border-style: solid; border-color: red;}
– p.two{border-style: solid; border-color:#98bf21;
• }
(d) CSS margin
• NB: The margin does not have a background color, and is completely transparent.
• The top, right, bottom, and left margin can be changed independently using
separate properties.
• To shorten the code, it is possible to specify all the margin properties in one
property. This is called a shorthand property.
<div id="top">
<h3>Cascading Style Sheets</h3>
</div>
HTML Code (2)
<div id = "intro">
<h4>What is CSS?</h4>
<img src = "css.png" height = "290" width = "780">
<p>CSS is short for Cascading Style Sheets. It is a language that
describes how HTML elements will be displayed on a webpage. Where
HTML will describe the content and structure of the page,
CSS describes the appearance, layout, and presentation of the
webpage.</p>
</div>
HTML Code (3)
<div id = "benefits">
<h4>Benefits of using CSS</h4>
<p><Some of the benefits of using CSS include:</p>
<ol>
<li>Easier coding</li>
<li>Consistency</li>
<li>Code reuse</li>
<li>Rich design and layout</li>
<li>Easier maintenance of webpages</li>
</ol>
</div>
HTML Code (4)
<div id = "apply">
<h4>Applying CSS to HTML</h4>
<p>CSS can be applied to HTML in 3 different ways
namely:</p>
<ul>
<li>Inline</li>
<li>Internally</li>
<li>Externally</li>
</ul>
</div>
HTML Code (5)
<div id="bottom">
<p>© University of Zimbabwe 2019</p>
</div>
}
body{
background-color: rgb(135,206,250);
margin: 20px;
h3{
text-align: center;
font-family: Georgia, "Times New Roman", Times, serif;
font-size:32px;
color: white;
}
h4{
text-align: center;
font-family: Georgia, "Times New Roman", Times,
serif;
color: white;
}
p, ol, ul{
font-style: italic;
font-size:11pt;
font-variant: normal;
font-weight: normal;
line-height: normal;
font-family: "Helvetica", sans-serif;
}