HTML 20121031
HTML 20121031
User Interfaces
Accessibility
Columnar layout
International Features
Mobile Devices
Precedence order
Inline styles
Embedded styles
External styles
Applying CSS to HTML/XHTML document
Inline styles
Are applied directly to the elements they affect.
Easy to use
General form:
<element style=“property1: value1;
property2: value2; … ; propertyn :
valuen”>
Eg:
<td style=“ border-style:solid; border-
width:1px; border-color:#000000;”>
Applying CSS to HTML/XHTML document
Embedded styles
Style definitions are embedded in a document head.
General form
<head>
<title></title>
<style>
CSS Rules
</style>
</head>
Applying CSS to HTML/XHTML document
External styles
A separate file is used to contain CSS rules
<link> element is used in the header of HTML/XHTML
element to indicate which style sheet to control the
appearance of the document.
General form
<head>
<title></title>
<link rel=“stylesheet” type=“text/css”
href=“myexternalstyle.css” />
</head>
Colors & Backgrounds
Colors and backgrounds
Foreground color
Is the color of an element.
In most cases is the color of the font
Property: color
Eg.
p.one {color: #C0C0C0}
p.two {color: blue}
Colors and backgrounds
Background Color
The background color of an element is the color of the
virtual page that the element is rendered upon
Property: background-color
Eg.
<p style=“background-color: blue;
color=white”>This paragraph will render
as white text on a blue background.</p>
Colors and backgrounds
Background Images
Images that is inserted in an element’s background.
Property: background-image
Eg.
p {
background-image: url(“bg.jpg”);
}
Colors and backgrounds
Background Images – Repeating background image
You can specify whether a background image is tiled or not.
Property: background-repeat
Values: repeat-x,repeat-y, repeat, no-repeat
Eg.
p {
background-image: url(“bg.jpg”);
background-repeat: repeat-x;
}
Colors and backgrounds
Background Images – Scrolling background image
You can allow the background to scroll when as element is
scrolled or disallow this behavior.
Property: background-attachment
Values: scroll, fixed.
Eg.
body {
background-image: url(“bg.jpg”);
background-attachment: fixed;
}
Colors and backgrounds
Background Images – Positioning background image
You can specify the position of the graphic in the element’s
background.
Property: background-position
Values:
top left, top center, right top, left
center, center, right center, bottom left,
bottom center, bottom right
Padding-right
Padding-top
Margin-right
Padding-left
Margin-left
Actual Content
Padding-bottom
Margin-bottom
CSS Box Model
The CSS Box Model (3)
Note:
When a bottom margin of one element meets the top
margin of another, only the larger of the two will show.
If they are the same size, only one of the margins will
show.
CSS Box Model
The CSS Box Model (4)
Eg (1)
<html>
<head>
<style>
h1, h2, b, p {
border: 5px solid black;
padding: 5px;
}
b {
background-color: yellow;
}
</style>
CSS Box Model
The CSS Box Model (5)
Eg (2)
</head>
<body>
<h1>Header 1</h1>
<h2>Header 2</h2>
<p>This is in <b>Paragraph 1</b></p>
<p>This is in <b>Paragraph 2</b></p>
</body>
</html>
CSS Box Model
The CSS Box Model (6)
Eg (3)
The page will be rendered as follows: