Web Technologies - ITC 351 Lecture - 6
Web Technologies - ITC 351 Lecture - 6
ITC351
Web Technologies
Lecture Six
Today’s Lecture
2.0
1.0 CSS
Overview Document
of CSS Structure
3.0 4.0
CSS Selectors Applying CSS
and to HTML
Declarations documents
Web Technologies Lecture Slides by: Maxwell Dorgbefu Jnr. 2
1
27-Apr-22
Outline of Instruction
Lecture Objectives
• By the end of the lecture, the student will
be able to:
– Explain CSS .
– Describe the CSS document structure.
– Identify CSS and write CSS style rules
– Describe how CSS files are applied to web
pages.
– Create and apply a CSS file to an HTML
document.
2
27-Apr-22
What is a CSS?
CSS is stands for Cascading Style Sheets.
CSS is a language that defines style
constructs such as fonts, colors and positions
which are used to describe how information
on a web page is formatted and displayed.
CSS is a style language that defines layout
and appearance of HTML documents.
CSS, is the recommended way to control the
presentation layer in web document projects
by creating robust style rules.
Web Technologies Lecture Slides by: Maxwell Dorgbefu Jnr.
Overview of CSS - 1
• A style sheet is a grouping of formatting
instructions that can control the
appearance of many HTML pages at once.
• CSS enables you to set a great number of
formatting characteristics that were never
possible before with any amount of effort.
3
27-Apr-22
4
27-Apr-22
5
27-Apr-22
Inline Styles
• An inline style can be used if a unique style is
to be applied to one single occurrence of an
element on a web page.
• To use inline styles, use the style attribute in
the start tag of the relevant element.
• The style attribute can contain any CSS
property value pairs.
• The example below shows how to change the
text color and the left margin of a paragraph:
<p style="color:blue;margin-left:20px;">This is a
paragraph.</p>
6
27-Apr-22
CSS Rule - 1
A rule or "rule set" is a statement that tells
browsers how to render particular elements
on an HTML page.
A rule set consists of a selector followed by a
declaration block.
Each declaration consists of a property and a
value.
A CSS declaration always ends with a
semicolon.
Declaration groups are surrounded by curly
brackets. Web Technologies Lecture Slides by: Maxwell Dorgbefu Jnr.
7
27-Apr-22
8
27-Apr-22
9
27-Apr-22
Descendant Selectors
A descendant selector matches any element
that is a descendant of another—in other
words, an element that is nested at any level
inside another.
To create a descendant selector, separate the
two selectors by a space, and putting the
descendant (nested) element on the right.
For example, the following style rule changes
the font size of paragraphs nested at any
level inside a <blockquote> tag:
blockquote p { font-size: 13px; }
Web Technologies Lecture Slides by: Maxwell Dorgbefu Jnr.
10
27-Apr-22
Pseudo-class Selectors
Pseudo-classes and pseudo-elements are
used to apply styles to elements based on
their state or position in the document.
Apply a pseudo-class or pseudo-element
by appending it to a basic selector.
For example, a:link applies the :link
pseudo-class to the <a> tags.
The p:first-letter applies the :first-letter
pseudo-element to the <p> tags.
Universal Selectors
Universal Selector is indicated with an
asterisk *.
The purpose of this selector is to make
style one time and it will be applied to
every single elements on the web page
The most common use of the universal
selector is to remove, or zero out, all
margins and padding. For example,
* {margin: 0px; padding: 0px;}
Web Technologies Lecture Slides by: Maxwell Dorgbefu Jnr.
11
27-Apr-22
Id Selector
An Id Selector is indicated by preceding its
name by the pound # sign.
Id selectors are used for page elements
that appear one time on a web page and
require unique formatting instructions.
For example, an Id selector could be :
#dare { text-indent: 3em }
This would be referenced in HTML by the
id attribute as shown here:
<p id= “dare” >Text indented 3em</p>
Web Technologies Lecture Slides by: Maxwell Dorgbefu Jnr.
Class Selector
A class selector’s name is preceded by a full stop (.).
Unlike Id selectors, a class selector can be applied to
several elements on a web page.
An example would be if you want to give all the
paragraphs on your web page the same styling.
.note {background-color: #013370;
color: white;
font-size: small;
}
This would be referenced in HTML by the class
attribute of the element:
<p class= “note” >This my paragraph</p>
12
27-Apr-22
Styling Background
• CSS background properties are used to
define the background effects of an
element.
• CSS properties used for background
effects:
– background-color
– background-image
– background-repeat
– background-attachment
– background-position
Background Color
• The background-color property specifies
the background color of an element.
• The background color of a page is
defined in the body selector:
body {background-color:#b0c4de;}
• The background color can be specified
by:
– Name - a color name, like "red"
– RGB - an RGB value, like "rgb(255,0,0)"
– Hex - a hex value, like "#ff0000“
13
27-Apr-22
Background Image
• The background-image property specifies
an image to use as the background of an
element.
• By default, the image is repeated so it
covers the entire element.
• The background image for a page can be
set like this:
• Example
body {background-image: url(‘path to the image file’);}
Styling Links - 1
Links can be style with any CSS property such
as color, font-family, and background-color.
Links can be styled differently depending on
what state they are in.
The four link states and the order of styling
them are:
a:link - normal, unvisited link
a:visited – link’s state when the user has visited it
a:hover – link’s state when the user mouses over it
a:active – link’s state the moment it is clicked
14
27-Apr-22
Styling Links - 2
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 */
When setting the style for several link
states, these order rules must be applied:
a:hover MUST come after a:link and a:visited
a:active MUST come after a:hover
Focus Questions
Visit https://www.w3schools.com and read
on the following:
1. Attribute selectors
2. Combinator selectors,
3. Pseudo-elements selector,
4. The CSS Box Model.
Kindly bring any questions you may have
to class for discussion.
15
27-Apr-22
16