Css Intro
Css Intro
Css Intro
• Sheet: Normally, CSS is a file separate from the HTML file – linked to the
HTML file through its <head> (exceptions apply)
Why CSS?
<em style="color:red;">dog</em>
Example: Inline Style
<h2 style="font-family:georgia; color:red;">
CAUTION: Stormy Weather!
</h2>
PREVIEW:
An inline style declaration like this one will affect only that particular
element. In other words, other <h2> elements on the page will not be
affected by this formatting.
<style>
em {
color: green; font-size:18px;
}
</style>
For internal style sheets, all formatting declarations are placed inside
the <style> element within the <head> section of the document. An
element is listed and all the styling information follows, surrounded by
opening and closing curly brackets, { }. A semicolon must still follow
each style declaration.
Styles declared in the internal style sheet will affect all matching
elements on the page. In this example, all <h2> elements on the
page will be displayed in Georgia font and in red color.
External
For external style sheets, a <link> tag is placed at the beginning of the
<head> section of the document specifying the external style sheet
(with a .css extension) to be used for formatting. The external style
sheet uses the same syntax as the internal style sheet when listing
elements and their styling.
pig.html lipstick.css
<html>
<head>
<link rel="stylesheet"
type="text/css"
href=“lipstick.css" />
</head>
…
</
html>
CSS Syntax
Selector Style Block
h1 {
color: red; Style
Element Values
Properties background: yellow;
}
h1 {
color: blue;
}
.legs {
font-weight: bold; background: pink;
}
#snout{
border: solid red;
}
• http://getfirebug.com/
• Right-click on an element,
then select “Inspect Element” from the dropdown
menu.
<span> Element tag
…
Colorzilla – Firefox Addon
• Easily find color values for elements in a
document.
• http://www.iosart.com/firefox/colorzilla/
• Click on the eyedropper icon in the
bottom-left of the browser and select any
color in your browser window.
• Right-click on the eyedropper for more
options.
Background Image Properties
• background-image: url(../location/of/image.jpg)
• background-repeat: tile image in
background
• background-position: vertical (top,
center, bottom, or size) horizontal (left,
center, right, or size)
• background-attachment: (scroll or fixed)
Font Properties
• monospace;
• font-style: italic;
• font-weight: (bold, bolder, lighter, or 100 – 900;)
• font-size: size;
• …or shorthand
• font: style weight size family;
Text Properties
…or shorthand
•list-style: position image
type
Border Properties
…or shorthand
• border(-top, -right, -left, -bottom): width
style color