Cascading Style Sheets (CSS) : Desain Web - SIF15012 Aryo Pinandito, ST, M.MT
Cascading Style Sheets (CSS) : Desain Web - SIF15012 Aryo Pinandito, ST, M.MT
Sheets (CSS)
Desain Web – SIF15012
Aryo Pinandito, ST, M.MT
Introduction to CSS
What is CSS?
Cascading Style Sheets (CSS):
is a simple mechanism for
adding style (e.g. fonts, colors,
layouts) to Web documents.
Internal
affect elements in an entire page
External
can affect multiple pages
Precedence
Local > Internal > External
Local Style Sheet
Example
<h1
style="color:white;
background:orange;
font-‐
weight:bold;">Internal
Style
Sheet
Applied
to
Header
1</h1>
Practice
add “text-align” property to make it centered
add “border” property to let it has black, 1px thick, solid
border at left, right, top, and bottom
Practice
Create a file called “mystyle.css” and do the
example in local style sheet, but as external style
sheet
Selector Type
Tag
redefines the look of a specific tag
body
{background-‐color:
#000000;}
Class
can apply to any tag
.indent{margin-‐right:5%;margin-‐left:
5%;}
In HTML, <p
class="indent">
Advanced
IDs, pseudo-class selectors
#myId
{
color:
#38608A;
}
a:hover
{
color:
#FF0000;
}
Values - Lenghts
Lengths [a number + unit identifier]
Unit identifier can be
em (font size of the relevant font),
ex (x-height of the relevant font),
px (pixels),
in (inches), cm (centimeter), mm,
pt (points, =1/72 in), pc (picas, 1 pc = 12 pt)
E.g.
h1
{
margin:
0.5em
},
h1
{
margin:
1ex
},
p
{
font-‐size:
12px
},
h2
{
line-‐height:
3cm
},
h4
{
font-‐size:
12pt
},
h4
{
font-‐size:
1pc
}
Values – Percentages &
URIs
Percentages [a number + %]
p
{
line-‐height:
120%
}
Examples
"this
is
a
'string'"
"this
is
a
\"string\""
'this
is
a
"string"'
'this
is
a
\'string\''
CSS Box Model
Box Model
Box Properties
margin : <length>
border : <style> <width> <color>
padding : <length>
width & height : <length>
Examples: p
{
margin:
50px;
padding:
30px;
float:
right;
height:
200px;
width:
400px;
border:
5px
solid
#006633;
}
Box Properties
Practice
Create an internal style called “boxStyle”
Insert an image that fits into one page.
Apply the “boxStyle” to the image
Color value: #9DACBF
Text Properties
font-family : <font name>, | <font name>, …
font-size : <length> | <percentage> | inherit
font-weight : normal | bold | lighter | 100 | 200 ...
normal = 400, bold = 700, lighter is relative
relative
An element with position: relative moves an element relative to its normal
position, so "left:20" adds 20 pixels to the element's LEFT position
absolute
An element with position: absolute is positioned at the specified coordinates
relative to its containing block. The element's position is specified with the
"left", "top", "right", and "bottom" properties
fixed
An element with position: fixed is positioned at the specified coordinates
relative to the browser window. The element's position is specified with the
"left", "top", "right", and "bottom" properties. The element remains at that
position regardless of scrolling. Works in IE7 (strict mode)
Positioning Properties
A floated box is shifted to the left or right until its
outer edge touches the containing block edge or the
outer edge of another float.
Example
.positionStyle
{
height:
400px;
width:
200px;
left:
50px;
top:
50px;
right:
50px;
bottom:
50px;
position:absolute;
float:
right;
}
Positioning Properties
Practice – thumbnail image
Create a table with only one cell
Insert the following image 10 times inside the only
cell of the table.
Outside
Background Properties
background-‐color:
<color>
|
transparent
|
inherit
background-‐image:
<uri>
|
none
|
inherit
background-‐position:
[[
<percentage>
|
<length>
|
left
|
center
|
right
]
[<percentage>
|
<length>
|
top
|
center
|
bottom
]?
]
|
[
[
left
|
center
|
right
]
||
[
top
|
center
|
bottom
]
]
|
inherit
background-‐repeat:
repeat
|
repeat-‐x
|
repeat-‐y
|
no-‐repeat
|
inherit
background-‐attachment:
scroll
|
fixed
|
inherit
Background Properties
Practice
body
{
background-‐image:
url(http://ptiik.ub.ac.id/labkcv/
assets/img/logo.png);
background-‐repeat:no-‐repeat;
color:
#FFFFFF;
background-‐position:center
center;
background-‐color:
#666666;
background-‐attachment:
fixed;
}
<div> and <span> tags
<div>
is a generic block-level tag
<span>
is a generic inline tag, it spans a series of characters
Example
.subTitle
{
font-‐family:
Georgia,
Times,
serif;
font-‐size:
14px;
font-‐weight:
bold;
color:
#960000;
}
<p>blah blah blah <span class="subTitle">some text in
different style</span> text text text text</p>
Assignment
Assignment: CSS
From the previous assignments, apply CSS to
beautify the page.
Apply CSS for:
Fonts
Color
Background
Border
Floats
Any Questions?