Lecture 4
Lecture 4
Lecture 4
HTML
• a { background-color: yellow; }
Selector property/value
separator
Declaration start Declaration end
Style Sheet Syntax Explained
selector
property value rule
CSS Syntax
selector {property: value;}
Three methods/Scopes
for adding css
• Local / inline
– confined to a single element (tag).
Inserted directly into the HTML element
(NO!!)
• Internal
– affect elements in an entire page (using the
<style> tag in the head section to affect a
single document).
• External
– can affect multiple pages. By linking to an
external .css file
• Precedence
– Local > Internal > External
Local /inline Style
Sheet
• Example
– <h1 style="color:white; background:orange; font-
weight: bold;">Internal Style Sheet Applied to Header
1</h1>
Full example:
<html><head><title>css style sheet</title></head>
<body>
<h1 style=“color:white; background:orange;font-
weight:bold;”> internal style sheet for H1</h1>
</body></html>
• Practice
1. add “text-align” property to make it
centered
2. add “border” property to let it have black,
1px thick, solid border at left, right, top, and
bottom
Internal Style Sheet
• How to create?
– Put <style> </style> tag between
<head> and </head> tags of your
HTML page
– Use type attribute to indicate the
style sheet type, usually
type=“text/css”
– Specify a default style sheet language
for the whole document by
<meta http-equiv="Content-Style-
Type" content="text/css" />
– Put your set of style sheet rules in
between <style> and </style> tags
Internal Style
Sheet
• Example
• <!Doctype html>
• <html>
• <head><title>css internal stylesheet</title>
• <style type=“text/css”>
• body{ background-color: #f4f4f4; color:#555555; font-
size:16px;
• Font-famiy:Arial, helvetica, sans-serif; font-weight:normal;
line-height:1.6em;}
• /*below on body is the short form of above code*/
• body{font: normal 16px Arial, Helvetica, sans-serif;}
h1{color:blue; font-family:courier new;
font-weight:bold; }
</style></head>
• <body>
• <h1>Hello world!! Welcome to css!!</h1>
• </body></html>
External Style
Sheet
• An external style sheet is simply a
text-only file that contains only
CSS rules.
• How to link to external style sheet?
– <link href=“URL of CSS File"
rel="stylesheet" type="text/css" />
• Practice
– Create a file called “mystyle.css” and
do the example in local style sheet,
but as external style sheet
External style sheet
• Mystyle.css file
body{ background-color:#f4f4f4; color:blue; line-
height:1.6em; font-family:arial, helvetica, sans-
serif; }
h1{ color:red; text-align:center; text-transform:
uppercase; }
Html document to be affected by the above
style sheet
<html><head><title>calling an external style
sheet </title>
<link rel=“stylesheet” type=“text/css”
href=“mystyle.css”>
</head><body>
<h1>welcome to web Design with simple css</h1>
</body> </html>
Example 2
• Style.css file
• Body { background-color:#f4f4f4; color:blue; line-
height:1.6em; font-family:arial, helvetica, sans-serif;
font-size:17px; font-weight:400; margin:0;}
.container { width:960px; /*80% more responsive and
better8*/ margin: auto;
.box-1{ background-color:#333; color:#fff;
border-right: 5px; red; solid; or
border: 5px; red; solid; this affects all the sides
Border-width:3px; border-bottom-width:5px;
padding:20px; font-style: italic;}
.box-1 h1{ font-family:tahoma; font-weight:800; text-
decoration: underline; letter-spacing:0.2em; word-
spacing:1em;}
Color assignment
modes
• style="background-color:yellow"
• style="font-size:10px"
• style="font-family:Times"
• style=“text-align:center”
• Background Color
• <body style="background-
color:yellow">
• The style attribute defines a style for
the <body> element.
• The new style attribute makes the "old"
bgcolor attribute obsolete.
HTML Style
Examples
cont…
Font Family, Color and Size
• <p style="font-family:courier new;
color:red; font-size:20px">
• The style attribute defines a style for the <p>
element.
• The new style attribute makes the old <font>
tag obsolete.
• Text Alignment
• <h1 style="text-align:center">
• The style attribute defines a style for the
<h1> element.
• The new style attribute makes the old "align"
attribute obsolete