By:
By:
AMELITA M. SANTOS
AMELITA M. SANTOS
(Faculty, School of Computer Science, Arellano
(Faculty, School of Computer Science, Arellano
University)
What is the web?
What is the web?
In a nutshell, theIn a nutshell, the webweb is a whole bunch onis a whole bunch on
interconnected computers talking to one another. interconnected computers talking to one another.
The computers (on the web) are The computers (on the web) are typically connectedtypically connected
by phone lines, digital satellite signals, cables, and by phone lines, digital satellite signals, cables, and other types of data-transfer mechanisms.
other types of data-transfer mechanisms.
A 'data-transfer mechanism' is a nerd's way of saA 'data-transfer mechanism' is a nerd's way of saying:ying:
a way to move information from point A t
a way to move information from point A to point B too point B to point C and so on.
point C and so on.
The computers that make up thThe computers that make up the web can be connectede web can be connected
all the time (24/7), or they can be connected only all the time (24/7), or they can be connected only periodically.
periodically.
The computers that are connected all tThe computers that are connected all the time arehe time are
typically called a 'server'. typically called a 'server'.
Servers are computers just like thServers are computers just like the one you're usinge one you're using
now to read this article,
now to read this article, with one major difference,with one major difference, they have a special software installed called 'server' they have a special software installed called 'server' software.
Web Design
Web Design
The skill of designing hypertext presentations of The skill of designing hypertext presentations of content that is delivered to an end-user through content that is delivered to an end-user through the World Wide Web.
the World Wide Web.
The process of designing Web pages, Web sites,The process of designing Web pages, Web sites, Web applications or multimedia for the Web
Web applications or multimedia for the Web andand may utilize multiple
may utilize multiple disciplines, such as animation,disciplines, such as animation, authoring, graphic
authoring, graphic design, human-computer design, human-computer
interaction, interaction design, photography, and interaction, interaction design, photography, and search engine.
Technologies Involved
Technologies Involved
Markup languages (such as HTML, XHTML andMarkup languages (such as HTML, XHTML and
XML) XML)
Style sheet languages (such asStyle sheet languages (such as CSSCSS and XSL)and XSL)
Client-side scripting (such as JavaScript andClient-side scripting (such as JavaScript and
VBScript) VBScript)
Server-side scripting (such as PHP and ASP)Server-side scripting (such as PHP and ASP)
Database technologies (such as Database technologies (such as MySQL)MySQL)
Multimedia technologies (such as Flash andMultimedia technologies (such as Flash and
Silverlight) Silverlight)
A
A style sheet language
style sheet language
is a computer
is a computer
language used to describe the
language used to describe the presentation of
presentation of
structured documents.
structured documents.
•• A structured document is a document whoseA structured document is a document whose
sections are clearly defined and categorized (also sections are clearly defined and categorized (also called "well-formed"). A program presenting the called "well-formed"). A program presenting the
document can present it in different styles because document can present it in different styles because the content has been
the content has been categorized.categorized.
One modern style sheet language with wide-
One modern style sheet language with
wide-spread use is
spread use is CSS (Cascading Style Sheets)
CSS (Cascading Style Sheets)
,,
which is used to style d
which is used to style documents written in HTML,
ocuments written in HTML,
or XHTML and other
What is CSS???
What is CSS???
CSS is
CSS is the acrothe acronym for: nym for: ‘Cascading ‘Cascading Style Style Sheets’Sheets’ CSS is an extension to basic
CSS is an extension to basic HTML that allows you toHTML that allows you to style your web pages.
style your web pages.
Style sheets let you place things exactly where you Style sheets let you place things exactly where you want them to be on the
want them to be on the page, using the distance inpage, using the distance in pixels from the top and t
pixels from the top and the left of the bhe left of the browser window.rowser window.
Styles defineStyles define how to displayhow to display HTML elementsHTML elements
Styles are normally stored inStyles are normally stored in Style SheetsStyle Sheets
External Style SheetsExternal Style Sheets can save you a lot of workcan save you a lot of work
External Style Sheets are stored inExternal Style Sheets are stored in CSS filesCSS files
Advantages of CSS
Advantages of CSS
CSS is an excellent addition to plain
CSS is an excellent addition to plain HTML.HTML.
With plain HTML you define the colors and sizes of text and tablesWith plain HTML you define the colors and sizes of text and tables
throughout your pages. If you want to change a certain element you will throughout your pages. If you want to change a certain element you will therefore have to work your way through the document and change it. therefore have to work your way through the document and change it.
With CSS you define the colors and sizes in "
With CSS you define the colors and sizes in "stylesstylesstylesstyles". As you". As you write your documents you refer to the styles. Thus, if you
write your documents you refer to the styles. Thus, if you changechange a certain style it will change the look
a certain style it will change the look of your entire site.of your entire site.
CSS offers much more detailed attributes than plain HTML for CSS offers much more detailed attributes than plain HTML for defining the look and feel of your site.
defining the look and feel of your site.
Finally, CSS can be written so the user will only
Finally, CSS can be written so the user will only need toneed to download it once - in
download it once - in the external style sheet document. Whenthe external style sheet document. When surfing the rest of your site the CSS
surfing the rest of your site the CSS will be cached on the will be cached on the usersusers computer, and therefore speed up the loadi
Things to Remember About
Things to Remember About
CSS:
CSS:
CSS code is simply written instructions that tells WebCSS code is simply written instructions that tells Web browsers (like FireFox and Internet Explorer) how
browsers (like FireFox and Internet Explorer) how toto display things on a page.
display things on a page.
For example:For example:
make text bold.make text bold.
position things a page.position things a page.
set the font style for a page or paragraph etc.set the font style for a page or paragraph etc.
The sister language to CSS is The sister language to CSS is HTML: code that tellsHTML: code that tells the Web browser WHAT is actually in th
HTML file
HTML file
<html><html><head><head>A sample HTML A sample HTML </head> </head> <body> <body> <h1>A simple HTML <h1>A simple HTML structure structure <br><br>This is <br><br>This is header 1 header 1 </h1> </h1> <h2>This is header <h2>This is header 2</h2> 2</h2> <p>This is a <p>This is a paragraph</p> paragraph</p>
Using Style
Using Style
Styles are set by adding the TAG:
Styles are set by adding the TAG:
<STYLE ...> <STYLE ...>
CSS Syntax
CSS Syntax
The CSS syntax is made up of three parts:
The CSS syntax is made up of three parts:
1. a selector
1. a selector
selector {property: value}
selector {property: value}
selector {property: value} selector {property: value}
The selector is normally the HTML The selector is normally the HTML element/tag youelement/tag you
wish to define, the property is
wish to define, the property is the attribute youthe attribute you wish to change, and each property can take
wish to change, and each property can take aa value.
value.
2. a property and a
2. a property and a value:value:
The property and value are separated by The property and value are separated by a colon,a colon,
and surrounded by curly braces: and surrounded by curly braces:
body {color: black}
body {color: black}
body {color: black} body {color: black}
CSS Syntax
CSS Syntax
Note:Note: If If the value the value is multiple is multiple words, put words, put quotes around quotes around thethe
value: value:
p {font-family: "sans serif"} p {font-family: "sans serif"}
Note:Note: If you wish to specify more than one property, you must If you wish to specify more than one property, you must
separate each property with a
separate each property with a semicolon. The example below semicolon. The example below shows how to define a center aligned paragraph, with a red text shows how to define a center aligned paragraph, with a red text color:
color:
p {text-align:center;color:red} p {text-align:center;color:red}
Note:Note: To make the style definitions more readable, you To make the style definitions more readable, you
can describe one property on each line, like this: can describe one property on each line, like this:
p
p { { text-align: text-align: center;center; color: black;
color: black;
font-family: arial } font-family: arial }
Grouping
Grouping
You You can can group group selectors selectors by sby separating eparating eacheach
selector with a comma. selector with a comma.
In the example below we have grouped all In the example below we have grouped all thethe
header elements. header elements.
All All odd header odd header elements wilelements will be l be displayed in displayed in greengreen
text color: text color:
h1,h3,h5 { color: green } h1,h3,h5 { color: green }
All All even heven header eader elements wielements will be ll be displayed displayed inin
green text color: green text color:
h2,h4,h6 { color: yellow} h2,h4,h6 { color: yellow}
The
The
class
class
Selector
Selector
With the class selector you can define different styles for
With the class selector you can define different styles for thethe same type of HTML element.
same type of HTML element.
Say that you would like to have two types
Say that you would like to have two types of paragraphs inof paragraphs in your document: one right-aligned paragraph, and one your document: one right-aligned paragraph, and one center-aligned paragraph. Here is how you can do it with styles:
aligned paragraph. Here is how you can do it with styles:
p.right {text-align: right} p.right {text-align: right} p.center {text-align: center} p.center {text-align: center}
You have to use the class attribute in your HTML
You have to use the class attribute in your HTML document:document:
<p class="right"> This paragraph will be <p class="right"> This paragraph will be
right-aligned. </p> aligned. </p>
<p class="center"> This paragraph will be <p class="center"> This paragraph will be center-alig
CSS Syntax
CSS Syntax
Note:Note: To apply more than one class per To apply more than one class per givengiven
element, the syntax is: element, the syntax is:
<p class="center bold"> This is a <p class="center bold"> This is a
paragraph. </p> paragraph. </p>
The paragraph above will be styled by
The paragraph above will be styled by the classthe class
"center" AND the class "
"center" AND the class "bold".bold".
You can also omit the tYou can also omit the tag name in the selector toag name in the selector to
define a style that will be
define a style that will be used by all HTML elementsused by all HTML elements that have a certain class. I
that have a certain class. In the example below, alln the example below, all HTML elements with class="center" will be HTML elements with class="center" will be center-aligned:
aligned:
.center {text-align: center} .center {text-align: center}
CSS Style
CSS Style
In the code below both the h1 element and the pIn the code below both the h1 element and the p
element have
element have class="center".class="center".
This means that both elements will follow the This means that both elements will follow the rules inrules in
the ".center" selector: the ".center" selector:
<h1 class="center"> This heading will be <h1 class="center"> This heading will be
center-aligned </h1> center-aligned </h1>
<p class="center"> This paragraph will also <p class="center"> This paragraph will also
be center-aligned. </p> be center-aligned. </p>
Add Styles to Elements
Add Styles to Elements
with Particular Attributes
with Particular Attributes
You can also apply styles to
You can also apply styles to HTML elements
HTML elements
with
with particular
particular attributes.
attributes.
The style rule below will
The style rule below will match all input
match all input
elements that have a type attribute with a
elements that have a type attribute with a
value of "text":
value of "text":
input[type="t
input[type="text"]
ext"] {background-
{background-color: blue}
The ID
The ID
Selector
Selector
You can also define styles for HTML elements
You can also define styles for HTML elements
with the id selector. The id s
with the id selector. The id selector is defined as
elector is defined as
a
a #
#
..
The style rule below will
The style rule below will match the element that
match the element that
has an id attribute with a value of "
has an id attribute with a value of "green":
green":
#green {color: green}
#green {color: green}
The style rule below will
The style rule below will match the p element
match the p element
that has an id with a value of "
that has an id with a value of "para1":
para1":
p#para1
p#para1
{
{ text-align: text-align: center;center;
color: red }
How to Insert a Style
How to Insert a Style
Sheet
Sheet
When a browser reads a style sheet, it willWhen a browser reads a style sheet, it will
format the document according to it. There are format the document according to it. There are three ways of inserting a style sheet:
three ways of inserting a style sheet:
1. External Style Sheet 1. External Style Sheet
An external style sheet is ideal when the style is applied toAn external style sheet is ideal when the style is applied to
many pages. With an external style sheet, you can change the many pages. With an external style sheet, you can change the look of an entire Web site by changing one file.
look of an entire Web site by changing one file.
2. Internal Style Sheet 2. Internal Style Sheet
An internal style sheet should be used when a single documentAn internal style sheet should be used when a single document
has a unique style. You define internal styles in the head has a unique style. You define internal styles in the head section by using the <style> tag.
section by using the <style> tag.
3. Inline Styles 3. Inline Styles
An inline style loses many of the advantages of style sheets byAn inline style loses many of the advantages of style sheets by
mixing content with presentation. Use this method sparingly, mixing content with presentation. Use this method sparingly, such as when a style is to be applied to a single occurrence of such as when a style is to be applied to a single occurrence of an element.
A. External Style
A. External Style
Sheet-1
Sheet-1
Each page must link to the style sheet
Each page must link to the style sheet
using the <link> tag. The <link> tag
using the <link> tag. The <link> tag
goes inside the head section:
goes inside the head section:
<head>
<head> <link rel="stylesheet"<link rel="stylesheet"
type="text/css" href="mystyle.css" type="text/css" href="mystyle.css" /> /> </head> </head>
The browser will read the styleThe browser will read the style
definitions from the file mystyle.css, and definitions from the file mystyle.css, and format the document according to it.
A. External Style
A. External Style
Sheet-2
Sheet-2
An external style sheet can be written in
An external style sheet can be written in
any text editor. The file should not contain
any text editor. The file should not contain
any html tags. Your style sheet should be
any html tags. Your style sheet should be
saved with a .css extension.
saved with a .css extension.
An example of a style sheet file is shown below:An example of a style sheet file is shown below: hr {color: sienna} hr {color: sienna} p {margin-left: 20px} p {margin-left: 20px} body {background-image: body {background-image: url("images/back40.gif")} url("images/back40.gif")}
Creating External CSS
Creating External CSS
file
file
External style sheets allow you to set all External style sheets allow you to set all the rules for the rules for
the entire site in one place, giving your site a the entire site in one place, giving your site a consistent look across all the
consistent look across all the pages.pages.
•
• You must create a text file called You must create a text file called mystyles.css.
mystyles.css.
•
• Type the styles code below into the f Type the styles code below into the file.ile. •
• Notice that this code does not have theNotice that this code does not have the <STYLE ...> tag in it:
<STYLE ...> tag in it: H2 { H2 { color:red; color:red; font-weight:900; font-weight:900; font-family:sans-serif; } font-family:sans-serif; }
myCSS.css
myCSS.css-- External CSS FileExternal CSS File
html html FileFile w/ external CSS w/ external CSS
Example
Example
OUTPUT of External CSS
B. Internal Style Sheet
B. Internal Style Sheet
You define internal styles in the head
You define internal styles in the head
section by using the <style> tag, like
section by using the <style> tag, like
this:
this:
<head> <style type="text/css"> <head> <style type="text/css"> hr {color: sienna}
hr {color: sienna}
p {margin-left: 20px} p {margin-left: 20px}
body {background-image: url("images/ body {background-image: url("images/
back40.gif")} back40.gif")} </style> </style> </head> </head>
B. Internal Style Sheet
B. Internal Style Sheet
Note:Note: A browser normally ignores unknown tags likeA browser normally ignores unknown tags like
an old browser that does not support styles, will ignore an old browser that does not support styles, will ignore the <style> tag, but the content of the <style> tag will the <style> tag, but the content of the <style> tag will be displayed on the page.
be displayed on the page.
It is possible to prevent an old
It is possible to prevent an old browser from displaying thebrowser from displaying the content by hiding it in the HTML comment element:
content by hiding it in the HTML comment element:
<head> <style type="text/css“> <head> <style type="text/css“>
<!--<!-- hr {color: sienna}hr {color: sienna}
p {margin-left: 20px} p {margin-left: 20px} body { background-image: body { background-image: url("images/back40.gif") } url("images/back40.gif") } -->
C. Inline Styles
C. Inline Styles
To use inline styles you use the style attribute in theTo use inline styles you use the style attribute in the
relevant tag. The style attribute can contain any CSS relevant tag. The style attribute can contain any CSS property.
property.
The example below shows how to change the color The example below shows how to change the color
and the left margin of a paragraph: and the left margin of a paragraph:
<p style="color: sienna; margin-left: <p style="color: sienna; margin-left: 20px">
20px">
This is a paragraph </p> This is a paragraph </p>
Single Tag CSS
Single Tag CSS
CSS can be defined for single tags by simply
CSS can be defined for single tags by simply
adding style="
adding style="styledefinition:styleattribute
styledefinition:styleattribute
;"
;"
to the tags.
to the tags.
S
S
ingle tag CSS is used when the style is used in aingle tag CSS is used when the style is used in asingle place on the entire site. single place on the entire site.
Look at this example:Look at this example:
<h2
<h2 style="font-fstyle="font-family:sans-serifamily:sans-serif;">;">
<h2
<h2 style="fostyle="font-family:sans-serifnt-family:sans-serif;">;"> Single Tag Example</h2>
Single Tag Example</h2>
Single Tag Example</h2> Single Tag Example</h2> It is It is It is It is <b style="font-size:20px;">NOT</b> me. <b style="font-size:20px;">NOT</b> me. <b style="font-size:20px;">NOT</b> me. <b style="font-size:20px;">NOT</b> me.
Multiple Style Sheets
Multiple Style Sheets
If some properties have been set foIf some properties have been set for the samer the same
selector in different style sheets, the values will be selector in different style sheets, the values will be inherited from the more specific style sheet.
inherited from the more specific style sheet.
For example, an external style sheet has theseFor example, an external style sheet has these properties for the h3 selector:
properties for the h3 selector:
h3 h3 { color: red; { color: red; text-align: left; text-align: left; font-size: 8pt } font-size: 8pt }
CSS Layers
CSS Layers
With CSS, it isWith CSS, it is
possible to work with possible to work with layers: pieces of HTML layers: pieces of HTML that are placed on top that are placed on top of the regular page
of the regular page with pixel precision. with pixel precision.