L02 CSS
L02 CSS
CSS
Joseph Tonien
Cascading Style Sheets
● Inline
● Document
● External
<body style="background-color:lightgrey;">
</p>
this is called a CSS property
Inline CSS
</p>
Inline CSS
</p>
Inline CSS
</p>
property:value
● We can specify more than one CSS property, separated by a semicolon (;)
<html>
<head>
<title>W3</title>
<style>
body {background-color:lightgrey;}
h1 {color:blue;}
p {border:1px solid black; padding:10px;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph</p>
</body>
</html>
External CSS
<html>
<head>
<title>W3</title>
<link rel="stylesheet" href="path/to/mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph</p>
</body>
</html>
mystyle.css
body {background-color:lightgrey;}
h1 {color:blue;}
p {border:1px solid black; padding:10px;}
Levels of CSS
body {
background-color:lightgrey;
}
h1 {
color:blue;
}
p {
border:1px solid black; each property on
padding:10px; a separate line
}
Simple selector
Example:
What are the descendants
of this element div ? <div>
Some text <i>italic</i> here.
<p>
Hi there <i>italic again</i>
</p>
<div>
This is the final <i>italic</i>.
</div>
</div>
Child-Parent
<E>
…
<F>
…
</E>
Example:
What are the children
of this element div ? <div>
Some text <i>italic</i> here.
<p>
Hi there <i>italic again</i>
</p>
<div>
This is the final <i>italic</i>.
</div>
</div>
Contextual Selector
Example: div i {
color:red;
<div> }
Some text <i>italic</i> here.
<p>
Hi there <i>italic again</i>
</p>
<div>
This is the final <i>italic</i>.
</div>
</div>
Contextual Selector
Example:
<div>
Some text <i>italic</i> here. div > i {
<p> color:red;
Hi there <i>italic again</i> }
</p>
<div>
This is the final <i>italic</i>.
</div>
</div>
Contextual Selector
Example: div.userInfo i {
color:red;
<div class="userInfo"> }
Some text <i>italic</i> here.
<p>
Hi there <i>italic again</i>
</p>
<div class="bankInfo">
This is the final <i>italic</i>.
</div>
</div>
Contextual Selector
Example: div.bankInfo i {
color:red;
<div class="userInfo"> }
Some text <i>italic</i> here.
<p>
Hi there <i>italic again</i>
</p>
<div class="bankInfo">
This is the final <i>italic</i>.
</div>
</div>
Contextual Selector
<ol>
<li>Item 1</li>
<li>Item 2</li>
</ol>
span
span.specialText {
color:red;
font-family:Ariel;
font-size:150%;
}
div
<div class="userInfo">
<p>This section displays user information.</p>
</div>
<div class="bankInfo">
<p>This section display bank information.</p>
</div>
div.userInfo {
border:1px solid black;
padding:10px;
}
div.bankInfo {
background-color:lightgrey;
}
Comments in CSS
A comment starts with /* and ends with */
p {
border:1px solid black;
color:blue;
}
/* This is
a multi-line
comment */
References
http://www.w3schools.com/css
https://en.wikipedia.org/wiki/Cascading_Style_Sheets