CSS Part 1
CSS Part 1
CSS (Part 1)
Content
2
CSS
What is CSS?
3
selector/element {
property: value;
}
Example
p {color:red;text-align:center;}
CSS Comments
6
body {
margin: 0;
padding: 0;
border-top: 1px solid #ff0;
}
Example
https://www.w3schools.com/css/tryit.asp?filename=trycss_syntax_elem
ent
Grouping of elements
9
Descendant Selector
body h1 { }
#navigation p {}
Child Selectors
div ol > p {}
Universal Selector
* {}
• Attribute Selectors
a[href=“http://home.org”]
Pseudo-Class Selectors
a:active {}
#nav:hover {}
Using Style Sheets
14
Embedded/Internal Styles
<style type=“text/css”>
body {}
</style>
Inline Styles
<p style=“font-size: 12px”>Lorem ipsum</p>
CSS Code
body{ background-color: gray;}
p { color: blue; }
h3{ color: white; }
HTML Code
<html>
<head>
<link rel="stylesheet" type="text/css" href="test.css" />
</head>
<body>
<h3> A White Header </h3>
<p> This paragraph has a blue font.
The background color of this page is gray because we changed it with
CSS! </p>
</body>
</html>
Embedded/Internal Styles Example
16
CSS Code
<html>
<head>
<style type="text/css">
p {color: white; }
body {background-color: black; }
</style>
</head>
<body>
<p>White text on a black background!</p>
</body>
</html>
Inline Styles Example
17
CSS Code
<html>
<head>
</head>
<body>
<p style="background: blue; color: white;">A new background
and font color with inline CSS</p>
</body>
</html>
Common Inline CSS Mistakes
18
CSS Code
h4 { background-color: white; }
p { background-color: #1078E1; }
background-position:right top;
background-attachment
27
Property Values
CSS Font
CSS Font
31
Serif Times New Roman Serif fonts have small lines at the ends on some characters
Georgia
Sans-serif Arial "Sans" means without - these fonts do not have the lines at the
Verdana ends of characters
Monospace Courier New All monospace characters have the same width
Lucida Console
Font Family
32
<html>
<head>
<style type="text/css">
p.serif{font-family:"Times New Roman",Times,serif;}
p.sansserif{font-family:Arial,Helvetica,sans-serif;}
</style>
</head>
<body>
<h1>CSS font-family</h1>
<p class="serif">This is a paragraph, shown in the Times New Roman
font.</p>
<p class="sansserif">This is a paragraph, shown in the Arial font.</p>
</body>
</html>
Font Style
34
h1 {font-size:40px;}
h2 {font-size:30px;}
p {font-size:14px;}
CSS Links
Links
50
Links can be style with any CSS property (e.g. color, font-
family, background-color).
Special for links are that they can be styled differently
depending on what state they are in.
The four links states are:
a:link - a normal, unvisited link
a:visited - a link the user has visited
a:hover - a link when the user mouses over it
a:active - a link the moment it is clicked
When setting the style for several link states, there are
some order rules:
a:hover MUST come after a:link and a:visited
a:active MUST come after a:hover
Example
51
<html>
<head>
<style type="text/css">
a:link {color:#FF0000;} /* unvisited link */
a:visited {color:#00FF00;} /* visited link */
a:hover {color:#FF00FF;} /* mouse over link */
a:active {color:#0000FF;} /* selected link */
</style>
</head>
<body>
<p><b><a href="default.asp.html" target="_blank">This is a link</a></b></p>
<p><b>Note:</b> a:hover MUST come after a:link and a:visited in the CSS
definition in order to be effective.</p>
<p><b>Note:</b> a:active MUST come after a:hover in the CSS definition in order
to be effective.</p>
</body>
</html>
52
CSS Lists
CSS Lists
53
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;}
Values for Unordered Lists
55
Value Description
None No marker
Disc Default. The marker is a filled circle
Circle The marker is a circle
Square The marker is a square
Values for Ordered Lists
56
Value Description
Armenian The marker is traditional Armenian numbering
Decimal The marker is a number
decimal-leading-zero The marker is a number padded by initial zeros (01, 02, 03, etc.)
The marker is traditional Georgian numbering (an, ban, gan,
Georgian
etc.)
lower-alpha The marker is lower-alpha (a, b, c, d, e, etc.)
lower-greek The marker is lower-greek (alpha, beta, gamma, etc.)
lower-latin The marker is lower-latin (a, b, c, d, e, etc.)
lower-roman The marker is lower-roman (i, ii, iii, iv, v, etc.)
upper-alpha The marker is upper-alpha (A, B, C, D, E, etc.)
upper-latin The marker is upper-latin (A, B, C, D, E, etc.)
upper-roman The marker is upper-roman (I, II, III, IV, V, etc.)
CSS Lists with Images
57
Sample:
http://www.w3schools.com/css/tryit.asp?filename=try
css_list-style-image
CSS List Position
58