Beruflich Dokumente
Kultur Dokumente
Web Programming
CSS (contd)
Inline styles
Internal styles (Embedded)
External styles
Browser default
Web Programming
Web Programming
CSS Syntax
Web Programming
CSS Syntax
Web Programming
CSS (contd)
Types of selectors
Web Programming
CSS (contd)
10
Web Programming
Format:
1. Styles for a particular element
tag_name.style_name { property: value }
Ex. p.color { color: green }
<p class=color>some text</p>
2. Styles for all elements
.style_name { property: value }
Ex. .color { color: blue }
<div class=color>some text</div>
<table class=color></table>
11
Web Programming
12
Web Programming
CSS (contd)
The Id selector
13
Web Programming
Format:
1. Styles for a particular element
tag_name#style_name { property: value }
Ex. p#color { color: green }
<p id=color>some text</p>
2. Styles for all elements
#style_name { property: value }
Ex. #color { color: blue }
<div id=color>some text</div>
<table id=color></table> possible ???
14
Web Programming
CSS (contd)
CSS comments
Format:
/* comment text */
/*This is a comment*/
p
{
text-align:center;
/*This is another comment*/
color:black;
font-family:arial;
}
15
Web Programming
16
Web Programming
Inline Styles
methods
declaring an individual elements format:
Attribute style
CSS (style) property
Web Programming
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4
5
-->
7
8
9
10
11
12
13
<body>
14
15
inline.html
(1 of 2)
16
17
18
-->
19
-->
20
21
22
</p>
23
1:1 relationship
However, the same document may have other style definitions
applied to it
1:M relationship
<head>
<style>
hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("images/back40.gif");}
</style>
</head>
22
Web Programming
property
value
rule
24
CSS (contd)
Web Programming
*/
2 /* An external stylesheet */
3
4 a
{ text-decoration: none }
5
6 a:hover { text-decoration: underline;
7
color: red;
background-color: #ccffcc }
9
10 li em
{ color: red;
11
font-weight: bold;
12
background-color: #ffffff }
13
14 ul
{ margin-left: 2cm }
15
16 ul ul
17
{ text-decoration: underline;
margin-left: .5cm }
styles.css
(1 of 1)
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4
5
-->
-->
7
8
9
10
11
12
13
14
15
<body>
16
external.html
(1 of 2)
17
18
<ul>
19
<li>Milk</li>
20
<li>Bread
21
<ul>
22
<li>White bread</li>
23
<li>Rye bread</li>
24
25
</ul>
26
</li>
27
<li>Rice</li>
28
<li>Potatoes</li>
29
30
</ul>
31
32
<p>
33
34
</p>
35
36
</body>
37 </html>
29
background-color: color
background-image: url(url)
Sets the background image for an element
background-repeat: repeat_type {repeat, repeat-x,
repeat-y, no-repeat}
background-attachment: attachment_type {scroll,
fixed}
Sets whether a background image is fixed or scrolls
with the rest of the page (default: scroll)
Web Programming
Background Color
The background-color property specifies the
background color of an element.
The background color of a page is defined in
the body selector:
body {background-color:#b0c4de;}
With CSS, a color is most often specified by:
h1 {background-color:#6495ed;}
p {background-color:#e0ffff;}
div {background-color:#b0c4de;}
30
Web Programming
Background Image
body {background-image:url('paper.gif');}
31
Example:
body
{
background-image:url('gradient2.png');
background-repeat:repeat-x;
}
32
Web Programming
}
33
Web Programming
34
Values of background-position
left top
left center
left bottom
right top
right center
right bottom
center top
center center
center bottom
Web Programming
body {
background:#ffffff url('img_tree.png') no-repeat right
top;
background-color
background-image
background-repeat
background-attachment
background-position
Web Programming
Text
color: color
36
Web Programming
h1 {text-decoration:overline}
h2 {text-decoration:line-through}
h3 {text-decoration:underline}
h4 {text-decoration:blink}
37
Web Programming
letter-spacing: value
text-decoration: decoration
white-space:
{none, underline,
overline, line-through, blink}
38
Web Programming
Example:
<!DOCTYPE html>
<html>
<head>
<style>
h1 {text-align:center;}
p.date {text-align:right;}
p.main {text-align:justify;}
</style>
</head>
<body>
<h1>CSS text-align Example</h1>
<p class="date">May, 2009</p>
<p class="main">In my younger and more vulnerable years my father gave me
some advice that I've been turning over in my mind ever since. 'Whenever you
feel like criticizing anyone,' he told me, 'just remember that all the people in this
world haven't had the advantages that you've had.'</p>
<p><b>Note:</b> Resize the browser window to see how the value "justify"
works.</p>
</body>
</html>
39
Web Programming
CSS (contd)
text-indent: value
The text-indent property specifies the indentation
of the first line in a text-block.
Note: Negative values are allowed. The first line
will be indented to the left if the value is negative.
Value: Defines a fixed indentation in px, pt, cm,
em, etc.
(16px=1em).
40
Web Programming
uppercase, lowercase}
The text-transform property controls the
capitalization of text.
Capitalize: Transforms the first character of
each word to uppercase
Example:
h1 {text-transform:uppercase;}
h2 {text-transform:capitalize;}
p {text-transform:lowercase;}
41
Web Programming
word-spacing: value
The word-spacing property increases or
decreases the white space between words.
Note: Negative values are allowed.
Example
Specify that the space between words in
paragraphs should be 30 pixels:
p
{
word-spacing:30px;
}
42
Web Programming
CSS Font
CSS font properties define the font family,
boldness, size, and the style of a text.
Font Family
The font family of a text is set with the fontfamily property.
Note: If the name of a font family is more
than one word, it must be in quotation
marks, like font-family: "Times New Roman".
More than one font family is specified in a
comma-separated list:
43
Web Programming
Eg:
p{font-family:"Times New Roman", Times,
serif;}
44
Web Programming
Font Style
The font-style property is mostly used to
specify italic text.
This property has three values:
p.normal {font-style:normal;}
p.italic {font-style:italic;}
p.oblique {font-style:oblique;}
45
Web Programming
Font Size
The font-size property sets the size of the
text.
Setting the text size with pixels, gives you full
control over the text size:
Eg:
h1 {font-size:40px;}
h2 {font-size:30px;}
p {font-size:14px;}
(16px=1em)
46
Web Programming
Web Programming
48
Web Programming
49
Web Programming
50
Web Programming
51
Web Programming
52
Web Programming
Borders
Box model
describes the rectangular boxes that are
generated for elements
53
Web Programming
54
Web Programming
55
Web Programming
Web Programming
Margin properties:
margin-top
margin-right
margin-bottom
margin-left
margin
57
Web Programming
58
Web Programming
59
Web Programming
60
Web Programming
Border properties
border-top-width ={thin,thick,medium,length}
border-right-width
border-bottom-width
border-left-width
border-width
Border width
61
Web Programming
H1 { border-width: thin }
/* thin thin
thin thin */
H1 { border-width: thin thick }
/* thin
thick thin thick */
H1 { border-width: thin thick medium }
62
Web Programming
63
border-top-color
border-right-color
border-bottom-color
border-left-color
border-color
Web Programming
border-style
border-style values:
64
65
Web Programming
66
Web Programming
67
Web Programming
border-style:dotted solid;
border-style:dotted;
Web Programming
border:<border-width>|<border-style>|<color>
The 'border' property is a shorthand property for setting the same width, color, and
style for all four borders of a box.
border-width
border-style (required)
border-color
Example
69
Web Programming
<!DOCTYPE html>
<html>
<head>
<style>
p.none {border-style:none;}
p.dotted {border-style:dotted;}
p.dashed {border-style:dashed;}
p.solid {border-style:solid;}
p.double {border-style:double;}
p.groove {border-style:groove;}
p.ridge {border-style:ridge;}
p.inset {border-style:inset;}
p.outset {border-style:outset;}
p.hidden {border-style:hidden;}
</style>
</head>
70
Web Programming
<p
<p
<p
<p
<p
<p
<p
<p
<p
<p
71
class="none">No border.</p>
class="dotted">A dotted border.</p>
class="dashed">A dashed border.</p>
class="solid">A solid border.</p>
class="double">A double border.</p>
class="groove">A groove border.</p>
class="ridge">A ridge border.</p>
class="inset">An inset border.</p>
class="outset">An outset border.</p>
class="hidden">A hidden border.</p>
Web Programming
P{
72
Web Programming
CSS Pseudo-classes
Syntax
selector:pseudo-class {property:value;}
Anchor Pseudo-classes
Example
Web Programming
:first-letter
Example
Select and style the first letter of every <p>
element:
p:first-letter
{
font-size:200%;
color:#8A2BE2;
}
74
Web Programming
75
font properties
color properties
background properties
margin properties
padding properties
border properties
text-decoration
text-transform
line-height
float
clear
Web Programming
:first-line Selector
76
font properties
color properties
background properties
word-spacing
letter-spacing
text-decoration
vertical-align
text-transform
line-height
clear
Web Programming
Example
Select and style the first line of every <p>
element:
p:first-line
{
background-color:yellow;
color:#ff0000;
font-variant:small-caps
}
77
Web Programming
font properties
color properties
background properties
word-spacing
letter-spacing
text-decoration
vertical-align
text-transform
line-height
clear
78
Web Programming
Web Programming
<!DOCTYPE html>
<html>
<head>
<style>
h1:before {content:url(smiley.gif);}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>The :before pseudo-element inserts content before an
element.</p>
<h1>This is a heading</h1>
<p><b>Note:</b> IE8 supports the content property
only if a !DOCTYPE is specified.</p>
</body>
</html>
80
Web Programming
Web Programming
display property
The display property defines how a certain
HTML element should be displayed.
82
none
block
flex
inline
list-item
The element is
displayed as a listitem, which means
that it has a bullet in
front of it
table
The element is
displayed as a table
83
Web Programming
<!DOCTYPE html>
<html>
<head>
<style>
p {display:inline}
</style>
</head>
<body>
<p>These two paragraphs generates inline boxes, and it
results in</p>
<p>no distance between the two elements.</p>
</body>
</html>
84
Web Programming
Positioning
85
position:static
Postion:relative
Postion:absolut
Postion:fixed
Web Programming
position:static
The default positioning for all elements is position:static,
which means the element is not positioned and occurs
where it normally would in the document.
Normally you wouldn't specify this unless you needed to
override a positioning that had been previously set.
Eg:
.static { position: static; }
<div class="static">staticis the default value. An
element withposition: static;is not positioned in any
special way. A static element is said to benot
positionedand an element with its position set to
anything else is said to bepositioned.
</div>
86
Web Programming
position:relative
.relative1 {
}
.relative2 { position: relative; top: -20px; left: 20px;
background-color: white; width: 500px;
}
87
Web Programming
88
Web Programming
position:absolute
When you specify position:absolute, the
element is removed from the document and
placed exactly where you tell it to go.
Eg: Let's move div a to the top right of the
page:
#div { position:absolute; top:0; right:0;
width:200px; }
89
Web Programming
.relative {
position: relative;
width: 600px;
height:
400px;
}
.absolute {
position: absolute;
top: 120px;
right: 0;
width: 300px;
height: 200px;
}
90
Web Programming
<div class="relative">
This element is relatively-positioned. If this element
wasposition: static;its absolutely-positioned child
would escape and would be positioned relative to the
document body.
<div class="absolute">
This element is absolutely-positioned. It's positioned
relative to its parent.
</div>
</div>
91
Web Programming
p.pos_fixed
{
position:fixed;
top:30px;
right:5px;
}
Fixed Positioning
92
Web Programming
Overlapping
Elements
An element can have a positive or negative stack order:
Example
img
{
position:absolute;
left:0px;
top:0px;
z-index:-1;
}
93
Web Programming
<!DOCTYPE html>
<html>
<head>
<style>
img {
position:absolute;
left:0px;
top:0px;
z-index:-1;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<img src="w3css.gif" width="100" height="140" />
<p>Because the image has a z-index of -1, it will be placed behind the
text.</p>
</body>
</html>
94
Web Programming
CSS
TheLists
CSS list properties allow you to:
List
95
Web Programming
Example
ul.a {list-style-type: circle;}
ul.b {list-style-type: square;}
ol.c {list-style-type: upper-roman;}
ol.d {list-style-type: lower-alpha;}
96
Web Programming
ul
{
list-style-image: url('sqpurple.gif');
}
97
Web Programming
}
Ul2{
list-style-type:circle;
list-style-position:outside;
}
98
Web Programming
side
outside
99
Web Programming
#Header {
margin:50px 0px 10px 0px;
padding:17px 0px 0px 20px;
border:1px dashed #999;
background-color:#eee;
}
#Content {
margin:0px 200px 50px 50px;
padding:10px;
border:1px dashed #999;
background-color: #eee;
}
#Menu {
position:absolute;
top:100px;
right:20px;
width:150px;
padding:10px;
background-color:#eee;
border:1px dashed #999;
}
<body>
<div id="Header">
<h1>Header.com </h1>
</div>
<div id="Content">
<h1>1.
Background</h1>
<p>The Computer Science program was started as one of the streams within the
Department of Mathematics, Faculty of Science, in the early 1980s. As
computers were introduced into governmental and nongovernmental institutions,
the need for trained manpower in Computer Science was very vital. Realizing
the growing need, a diploma program in Computer Science was launched in the
evening program in 1983. In addition, the Department also started to offer
Computer Science as a minor program for Physics, Statistics, and Library Science
students. In 1993, a Degree program in Computer Science was launched.
</p>
<div id="Menu">
<p><a hre="">Link 1</a></p>
<p><a hre="">Link 2</a></p>
<p><a hre="">Link 3</a></p>
<p><a hre="">Link 4</a></p>
<p><a hre="">Link 5</a></p>
<p><a hre="">Link 6</a></p>
</div>
</body>
101
Web Programming
102
Web Programming
103
Web Programming
.content {
position:relative;
width:auto;
min-width:120px;
margin:0px 210px 20px 170px;
border:1px solid black;
padding:10px;
z-index:3; /* This allows the content to overlap the right menu in narrow windows in good browsers. */
}
#navAlpha {
position:absolute;
width:128px;
top:20px;
left:20px;
border:1px dashed black;
background-color:#eee;
padding:10px;
float:left;
z-index:2;
}
#navBeta {
position:absolute;
width:168px;
top:20px;
right:20px;
border:1px dashed black;
background-color:#eee;
padding:0px;
z-index:1;
}
104
Web Programming
<div id="navAlpha">
<p><a hre="">Link 1</a></p>
<p><a hre="">Link 2</a></p>
<p><a hre="">Link 3</a></p>
<p><a hre="">Link 4</a></p>
<p><a hre="">Link 5</a></p>
<p><a hre="">Link 6</a></p>
</div>
<div class="content">
<h1>1.
Background</h1>
Web Programming
<div class="content">
<p>The Computer Science program was started as one of the streams within
the Department of Mathematics, Faculty of Science, in the early 1980s. As
computers were introduced into governmental and nongovernmental
institutions, the need for trained manpower in Computer Science was very
vital. Realizing the growing need, a diploma program in Computer Science
was launched in the evening program in 1983.
</p>
</div>
<div class="content">
<p><a hre="">Some other links can go here..</a></p>
</div>
<div id="navBeta">
<p><a hre="">Link 1</a></p>
<p><a hre="">Link 2</a></p>
<p><a hre="">Link 3</a></p>
<p><a hre="">Link 4</a></p>
<p><a hre="">Link 5</a></p>
<p><a hre="">Link 6</a></p>
</div>
106
Web Programming