Itec50 Lesson 6 Part 1
Itec50 Lesson 6 Part 1
CSS
Part I
Romel Griego
Instructor I
Department of Industrial and Information Technology
CSS
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
CSS Solved a Big Problem
p {
color: red;
text-align: center;
}
CSS Selectors
CSS Selectors
p {
text-align: center;
color: red;
}
The CSS id Selector
The CSS id Selector
#para1 {
text-align: center;
color: red;
}
.center {
text-align: center;
color: red;
}
The CSS class Selector
p.center {
text-align: center;
color: red;
}
The CSS class Selector
* {
text-align: center;
color: blue;
}
The CSS Grouping Selector
The CSS Grouping Selector
h1 {
text-align: center;
color: red;
}
p {
text-align: center;
color: red;
}
The CSS Grouping Selector
h1, h2, p {
text-align: center;
color: red;
}
All CSS Simple Selectors
• External CSS
• Internal CSS
• Inline CSS
1. External CSS
1. External CSS
/* */
HTML and CSS Comments
From the HTML tutorial, you learned that you can add
comments to your HTML source by using the
<!--...--> syntax.
<h1 style="background-color:DodgerBlue;">Hello
World</h1>
<p style="background-color:Tomato;">Lorem
ipsum...</p>
CSS Backgrounds
CSS Backgrounds
The CSS background properties are used to add
background effects for elements.
body {
background-color: lightblue;
}
Opacity / Transparency
Opacity / Transparency
• margin-top
• margin-right
• margin-bottom
• margin-left
Margin - Individual Sides
All the margin properties can have the following
values:
• auto - the browser calculates the margin
• length - specifies a margin in px, pt, cm, etc.
• % - specifies a margin in % of the width of the
containing element
• inherit - specifies that the margin should be
inherited from the parent element
div {
width: 300px;
margin: auto;
border: 1px solid red;
}
The inherit Value
This example lets the left margin of the <p class="ex1">
element be inherited from the parent element (<div>):
div {
border: 1px solid red;
margin-left: 100px;
}
p.ex1 {
margin-left: inherit;
}
CSS Padding
CSS Padding
Padding is used to create space around an element's
content, inside of any defined borders.
With CSS, you have full control over the padding. There
are properties for setting the padding for each side of
an element (top, right, bottom, and left).
Padding - Individual Sides
CSS has properties for specifying the padding for each
side of an element:
• padding-top
• padding-right
• padding-bottom
• padding-left
Padding - Individual Sides
All the padding properties can have the following
values:
• padding-top
• padding-right
• padding-bottom
• padding-left
Padding - Shorthand Property
padding: 25px 50px 75px 100px
• top padding is 25px
• right padding is 50px
• bottom padding is 75px
• left padding is 100px
padding: 25px;
• all four paddings are 25px
CSS Height, Width and Max-width
CSS Height, Width and Max-width
div {
width: 320px;
height: 50px;
padding: 10px;
border: 5px solid gray;
margin: 0;
}
Here is the calculation:
320px (width of content area)
+ 20px (left padding + right padding)
+ 10px (left border + right border)
= 350px (total width)
body {
color: blue;
}
h1 {
color: green;
}
Text Color and Background Color
In this example, we define both the background-
color property and the color property:
body {
background-color: lightgrey;
color: blue;
}
h1 {
background-color: black;
color: white;
}
CSS Fonts
Font Selection is Important
• Choosing the right font has a huge impact on how
the readers experience a website.
.p1 {
font-family: "Times New Roman", Times,
serif;
}
CSS Icons
How To Add Icons
a {
color: hotpink;
}
CSS Links
/* unvisited link */
a:link {
color: red;
}
/* visited link */
a:visited {
color: green;
}
CSS Links
/* selected link */
a:active {
color: blue;
}
CSS Links
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
Text Decoration
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: underline;
}
Different types of cursors
<span style="cursor: auto">auto</span><br>
<span style="cursor: crosshair">crosshair</span><br>
<span style="cursor: default">default</span><br>
<span style="cursor: e-resize">e-resize</span><br>
<span style="cursor: help">help</span><br>
<span style="cursor: move">move</span><br>
<span style="cursor: n-resize">n-resize</span><br>
<span style="cursor: ne-resize">ne-resize</span><br>
<span style="cursor: nw-resize">nw-resize</span><br>
Different types of cursors
<span style="cursor: pointer">pointer</span><br>
<span style="cursor: progress">progress</span><br>
<span style="cursor: s-resize">s-resize</span><br>
<span style="cursor: se-resize">se-resize</span><br>
<span style="cursor: sw-resize">sw-resize</span><br>
<span style="cursor: text">text</span><br>
<span style="cursor: w-resize">w-resize</span><br>
<span style="cursor: wait">wait</span>
CSS Lists
CSS Lists
HTML Lists and CSS List Properties
ul.a {
list-style-type: circle;
}
Different List Item Markers
ul.b {
list-style-type: square;
}
ol.c {
list-style-type: upper-roman;
}
ol.d {
list-style-type: lower-alpha;
}
An Image as The List Item Marker
ul {
list-style-image: url('sqpurple.gif');
}
Position The List Item Markers
outside inside
Remove Default Settings