Tutorial Css
Tutorial Css
1. Pengenalan CSS
CSS merupakan kepanjangan dari Cascading Style Sheet yaitu suatu dokumen yang digunakan
untuk melakukan pengaturan halaman web.
Apa itu CSS :
CSS singkatan dari Cascading Style Sheets
Styles didefinisikan bagaimana manampilkan elemen HTML
Styles umumnya disimpan ke dalam Style Sheet
Styles ditambahkan HTML untuk membantu pekerjaan
External Style Sheets dapat membantu banyak pekerjaan
ExternalStyle Sheet disimpan dalam CSS files
Multiple Style dapat didefinisi banyak jendela menjadi satu
Menggunakan CSS tidak memerlukan perangkat lunak tertentu karena merupakan script yang telah
embeded dengan HTML. Cukup menggunakan aplikasi seperti note pad, anda sudah mampu
menciptakan script CSS sendiri
Style Sheets merupakan feature yang sangat penting dalam membuat Dynamic HTML. Meskipun
bukan merupakan suatu keharusan dalam membuat web, akan tetapi penggunaan style sheets
merupakan kelebihan tersendiri.
Suatu style sheet merupakan tempat dimana anda mengontrol dan memanage style-style yang ada.
Style sheet mendeskripsikan bagaiman tampilan document HTML di layar. Anda juga bias
menyebutnya sebagai template dari documents HTML yang menggunakanya.
Anda juga bisa membuat efek-efek sepsial di web anda dengan menggunakan style sheet. Sebagai
contoh anda bisa membuat style sheet yang mendefinisikan style untuk <H1> dengan style bold dan
italic dan berwarna biru. Atau pada tag <P> yang akan di tampilkan dengan warna kuning dan
menggunakan font verdana dan masih banyak lagi yang bias anda lakukan dengan style sheet.
Secara teoritis anda bisa menggunakan style sheet technology dengan HTML. Akan tetapi pada
prakteknya hanya Cascading Style Sheet (CSS) technology yang support pada hampir semua web
Browser. Karena CSS telah di setandartkan oleh World Wide Web Consortium (W3C) untuk di
gunakan di web browser.
Pada perkembangannya CSS sudah masuk level 3 untuk sekarang, dimana dimulai CSS level 1 atau
yang sering di sebut CSS aja, kemudian level 2 yang merupakan penyempurnaan dari CSS level
sebelumnya, yaitu CSS level 1.
CSS merupakan alternatif bahasa pemrograman web masa yang akan datang, dimana mempunyai
banyak keuntungan, diantaranya :
1Ukuran file lebih kecil
2Load file lebih cepat
3Dapat berkolaborasi dengan JavaScript
4Pasangan setia XHTML
5Menghemat pekerjaan tentunya, dimana hanya membuat 1 halaman CSS.
6Mudah mengganti-ganti tampilan dengan hanya merubah file CSS nya saja.
7Dan banyak lagi yang lainnya.
MULOK/XII/08-09
Hal:1
Contoh:
1.
p {margin-left: 20px}
3.
p {text-align:center;color:red}
5.
body{ color:b
lack}
h1,h2,h3,h4,h
5,h6
{
color: green
}
e
n
u
l
i
s
k
a
n
a
.
l
a
n
g
Jika nilai /value lebih dari satu s
u
kata, maka gunakan tanda
n
petik di antara nilai(2)
g
s
c
r
i
p
t
C
Jika selector lebih dari dan
mempunyai property dan value S
S
yang sama maka gunakan
tanda koma(6).
d
i
Ada tiga cara penempatan kode
CSS dalam HTML, yaitu :
1. Internal CSS
Y
a
i
t
u
m
4.
6.
p
{
text-align: center;
color: black; fontfamily: arial
}
Catatan:
P{fontfamily:sans
serif}
f
i
l
e
H
T
M
L
n
y
i
t
l
e
>
C
o
n
t
o
h
<
h
t
m
l
>
<
h
e
a
d
>
<
t
i
t
l
e
>
B
e
l
a
j
a
r
C
S
S
<
/
t
<
s
t
y
l
e
t
y
p
e
=
t
e
x
t
/
c
s
s
>
p {color:
white; }
b
o
d
y
{
b
a
c
k
g
r
o
u
n
d
c
o
l
o
r
:
b
l
a
c
k
;
}
<
/
s
t
y
l
e
>
<
/
h
e
a
d
>
<
b
o
d
y
>
<
p
>
S
e
l
a
m
a
t
C
S
S
<
/
p
>
<
/
b
o
d
y
>
</html>
D
a
t
a
n
gMULOK/XII/08-09
Hal:2
2. External CSS
Yaitu memanggil file CSS dari tempat/folder/lokasi lain, dengan kata lain file CSS terpisah dengan
file HTML. Browser akan membaca definisi style dari file test.css dan akan mengikuti format
tersebut.Eksternal style ditulis di text editor lain dengan ekstention .css Untuk lebih jelasnya kita
lihat contoh dibawah ini:
<html>
<head>
<title>Belajar CSS</title>
<link rel=stylesheet type=text/css
href=test.css/> </head>
<body>
<h3> Selamat Datang CSS </h3>
</body>
</html>
3. Inline CSS
Yaitu penulisan kode CSS dalam tag HTML. Lihat contoh dibawah ini:
<html>
<head>
<title>Belajar
CSS</title> </head>
<p style=background: blue; color: white;>Style Menggunakan
CSS</p>
</body>
</html>
Class Selector
Dengan class selector dapat mendefinisikan perbedaan style untuk tag elemen html yang sama.
Misalnya, dua type paragraph dalam dokumen.Yang satu paragraph align-right dan yang satu
paragraph align-center.
Contoh:
.right
This paragraph
p.right {text-align: right}
will be right{text-align:
atau
aligned. </p>
p.center {text-align: center}
right}
<p class="center">
.center
This
paragraph
{text-align:
Penggunaan atribut class di dalam dokumen html
will be centercenter}
aligned. </p>
<p class="right">
o
p
c
l
a
Catatan:
l
d
r
a
"
a
Jangan memberi nama class
s
>
g
s
r
dengan angka.
=
T
a
"
h
p
Memberikan kata/kalimat lebih
c
i
h
dari satu class, penulisannya
e
s
.
n
adalah:
t
i
<
e
s
/
r
p
<
a
>
p
b
MULOK/XII/08-09 Hal:3
Hal:4
Description
Sets the color of a text
Sets the text direction
line-height
letter-spacing
text-align
text-decoration
text-indent
text-shadow
text-transform
MULOK/XII/08-09
unicode-bidi
white-space
word-spacing
Values
color
ltr
rtl
normal
number
length
%
normal
length
left
right
center
justify
none
underline
overline
line-through
blink
length
%
none
color
length
none
capitalize
uppercase
lowercase
IE
3
6
F
1
1
N
4
6
W3C
1
2
Hal:5
normal
embed
bidi-override
Sets how white space inside normal
an element is handled
pre
nowrap
Increase or decrease the
normal
4 1
length
Description
Sets the sides of an element
where other floating elements
are not allowed
cursor
display
Values
Left
right
both
none
url
auto
crosshair
default
pointer
move
e-resize
ne-resize
nw-resize
n-resize
se-resize
sw-resize
s-resize
w-resize
text
wait
help
none
inline
block
list-item
run-in
compact
marker
table
inline-table
table-row-group
table-header-group
table-footer-group
table-row
table-column-group
table-column
table-cell
table-caption
MULOK/XII/08-09
Hal:6
IE
4
F
1
N
4
W3C
1
float
position
visibility
left
right
none
static
relative
absolute
fixed
visible
hidden
collapse
border-spacing
caption-side
MULOK/XII/08-09
empty-cells
Description
Sets whether the table
borders are collapsed into a
single border or detached as
in standard HTML
Sets the distance that
separates cell borders (only
for the "separated borders"
model)
Sets the position of the table
Values
collapse
separate
IE
5
F
1
N
7
W3C
2
length length
5M 1
top
5M 1
caption
bottom
left
right
show
hide
5M
6 2
Hal:7
table-layout
model)
Sets the algorithm used to
display the table cells, rows,
and columns
auto
fixed
Description
A shorthand property for
setting all background
properties in one declaration
Values
IE
background-color
4
background-image
background-repeat
background-attachment
background-position
scroll
4
fixed
Hal:8
F
1
N
6
W3C
1
background-position
background-repeat
Description
A shorthand property for
setting all of the properties
for a font in one declaration
Values
font-style
font-variant
font-weight
font-size/line-height
font-family
caption
icon
menu
message-box
small-caption
MULOK/XII/08-09 Hal:9
IE
4
F
1
N
4
W3C
1
font-family
font-size
status-bar
family-name
generic-family
xx-small
x-small
small
font-size-adjust
font-stretch
font-style
font-variant
font-weight
medium
large
x-large
xx-large
smaller
larger
length
%
Specifies an aspect value for none
an element that will preserve number
the x-height of the firstchoice font
Condenses or expands the
normal
current font-family
wider
narrower
ultra-condensed
extra-condensed
condensed
semi-condensed
semi-expanded
expanded
extra-expanded
ultra-expanded
Sets the style of the font
normal
italic
oblique
Displays text in a small-caps normal
font or a normal font
small-caps
Sets the weight of a font
normal
bold
bolder
lighter
100
200
300
400
500
600
700
800
900
Contoh:
<html>
<head>
<style type="text/css">
p
{
font: italic small-caps 900 20px arial
}
</style>
</head>
<body>
<p>This is a
paragraph</p> </body>
</html>
Catatan: Property ini juga mempunyai enam nilai: "line-height", penulisan spasi dengan garis.
Contoh:
P
{
font: 12px arial
}
p
{
font: italic small-caps bold 12px arial
}
p
{
font: oblique small-caps 900 12px/14px arial
}
p
{
font: menu
}
Possible Values
Value
Description
font-style
Sets the properties for a font. The line-height value sets the space between lines.
font-variant
The value can be a number, a %, or a font size.
font-weight
Default value: Browser dependent
font-size/lineheight
font-family
Caption
Defines the font that are used by captioned controls (like buttons, drop-downs,
etc.)
Icon
Defines the fonts that are used by icon labels
Menu
Defines the fonts that are used by dropdown menus
Message-box
Defines the fonts that are used by dialog boxes
small-caption
status-bar
Defines the fonts that are used by window status bars
MULOK/XII/08-09
Hal:11
Description
A shorthand property for
setting all of the properties
for a list in one declaration
Sets an image as the list-item
marker
Sets where the list-item
marker is placed in the list
Sets the type of the list-item
marker
Values
list-style-type
list-style-position
list-style-image
none
url
inside
outside
none
disc
circle
square
decimal
decimal-leading-zero
lower-roman
upper-roman
lower-alpha
upper-alpha
lower-greek
lower-latin
upper-latin
hebrew
armenian
georgian
cjk-ideographic
MULOK/XII/08-09 Hal:12
IE
4
F
1
N
6
W3C
1
hiragana
katakana
hiragana-iroha
katakana-iroha
auto
length
marker-offset
Hal:13
</head>
<body>
<p class="one">One-colored border!</p>
<p class="two">Two-colored border!</p>
<p class="three">Three-colored border!
</p> <p class="four">Four-colored border!
</p> <p><b>Note:</b> The "bordercolor"</p> </body>
</html>
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: Penomoran "W3C" kolom indikasi yang mana CSS merekomendasikan definisi property (CSS1
or CSS2).
Property
border
border-bottom
border-bottom-color
border-bottom-style
border-bottom-width
border-color
border-left
border-left-color
border-left-style
border-left-width
border-right
border-right-color
Description
A shorthand property for
setting all of the properties
for the four borders in one
declaration
A shorthand property for
setting all of the properties
for the bottom border in one
declaration
Sets the color of the bottom
border
Sets the style of the bottom
border
Sets the width of the bottom
border
Sets the color of the four
borders, can have from one
to four colors
A shorthand property for
setting all of the properties
for the left border in one
declaration
Sets the color of the left
border
Sets the style of the left
border
Sets the width of the left
border
A shorthand property for
setting all of the properties
for the right border in one
declaration
Sets the color of the right
border
MULOK/XII/08-09
border-right- Sets the style
style
of the right
border-style
border
border-right- Sets the width
width
of the right
thin
border
medium
thick
length
Values
border-width
border-style
border-color
IE
4
F
1
N
4
W3C
1
border-bottom-width
border-style
border-color
border-color
border-style
thin
medium
thick
length
color
border-left-width
border-style
border-color
border-color
border-style
thin
medium
thick
length
border-right-width
border-style
border-color
border-color
Hal:14
4
border-style
border-top
border-topcolor
border-topstyle
border-topwidth
border-width
CSS Margin
Properties
The CSS margin properties define the space around elements. It is possible to use negative values
to overlap content. The top, right, bottom, and left margin can be changed independently using
separate properties. A shorthand margin property can also be used to change all of the margins at
once.
Note: Netscape and IE give the body tag a default margin of 8px. Opera does not! Instead, Opera
applies a default padding of 8px, so if one wants to adjust the margin for an entire page and have it
display correctly in Opera, the body padding must be set as well!
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property is
defined (CSS1 or CSS2).
Property
Description
Values
IE F N W3C
margin
A shorthand property for
margin-top
4
1 4 1
setting the margin properties margin-right
in one declaration
margin-bottom
Hal:15
MULOK/XII/08-09
margin-left
margin-bottom
margin-left
margin-right
margin-top
MULOK/XII/08-09
Hal:16