Chapter 3
Chapter 3
Chapter Three
Cascading Style sheet (CSS)
By Tesfahun N.
Outline
XHTML.
Why css
❖ Improve flexibility
CSS Syntax
❖ Some CSS styles are inherited and some not
etc.>
Style Sheets Syntax
❖ Stylesheets consist of rules, selectors, declarations(
properties and values)
7
Selectors (2)
❖ Three primary kinds of selectors:
➢ By tag (type selector):
h1 { font-family: verdana,sans-serif; }
➢ By element id:
#idname{….
➢ By element class name (only for HTML):
.clasname {border: 1px solid red}
❖ Selectors can be combined with commas:
h1, .link, #top-link {font-weight: bold}
8
Values in the CSS Rules
❖ Colors are set in RGB format (decimal or hex):
11
Embedded Styles
❖text-decoration
✓ Values: none, underline, line-trough, overline, blink
❖text-align
✓ Values: left, right, center, justify
24
Shorthand Font Property
❖ Font
❖Shorthand rule for setting multiple font
properties at the same time
font:italic normal bold 12px/16px verdana
❖is equal to writing this:
font-style: italic;
font-variant: normal;
font-weight: bold;
font-size: 12px;
line-height: 16px;
font-family: verdana;
25
Part II
.
.
.
.
Backgrounds
❖ background-image
✓ URL of image to be used as background, e.g.:
✓ background-image:url("back.gif");
❖ background-color
✓ Using color
❖ background-repeat
❖ background-attachment
27
✓ fixed / scroll
Backgrounds (2)
❖ Background-position: specifies vertical and horizontal
position of the background image
– border-top-style, border-left-color, …
29
Width and Height
❖ width – defines numerical value for the width of
element, e.g. 200px
33
Positioning
❖ position: defines the positioning of the element in the
page content flow
➢ static (default)
35
Clear
❖ clear
• Clearing floats
37
Visibility
❖ visibility
38
Display
❖ display: controls the display of the element and the way
it is rendered and if breaks should be placed before and
after the element
➢ inline: no breaks are placed before and after (<span>
is an inline element)
➢ block: breaks are placed before AND after the
element (<div> is a block element)
40
Other CSS Properties
❖ cursor: specifies the look of the mouse cursor when
placed over the element
}
CSS: Creating Navigation Bars
<ul id="navbar">
<li><a href="/tests">Home</a></li>
<li><a href="/library">help</a></li>
<li><a href="/testimonials">login</a></li>
</ul>
Cont..
#navbar {
list-style-type: none;
margin: 0;
padding: 0;
width: 200px;
background-color: #EEEEEE;
}
Cont..
ul#navbar li a {
display: block;
color: #000000;
font-weight:bold;
padding: 8px 16px;
text-decoration: none;
}
Cont..
ul#navbar li a:hover {
background-color: orange;
color: white;
}
Cont..
ul#navbar li {
display: inline;
CSS Measuring Units
❖ CSS Units