CSS 1
STMIK Asia Malang - 2013
CSS adalah standar pembuatan dan pemakaian style (font, warna, jarak baris, dll) untuk dokumen terstruktur CSS memisahkan style sebuah dokumen dari content dokumen itu sendiri CSS memudahkan pembuatan dan pemeliharaan dokumen web Setiap User Agent mempunyai default style sheet Pendefinisian rule CSS pada sebuah dokumen akan menimpa rule pada default style sheet
Referensi CSS
Spesifikasi CSS1,
http://www.w3.org/TR/REC-CSS1 http://www.w3.org/TR/REC-CSS2
Spesifikasi CSS2,
Sintak CSS
Selector menggunakan tag HTML. Properti adalah atribut yang ingin diubah. Setiap atribut dapat memiliki nilai (value)
STMIK Asia Malang -
Sintak Rule
Contoh rule :
h1 { color: blue } Keterangan: Selector : h1 Property : color Value : blue
2.
3.
Grouping (pengelompokan) :
Selector : h1, h2, h3 { font-family: arial } Declaration : h1 { font-weight: bold; font-size: 14pt } Value : h1 { font: bold 12pt arial }
Inheritance (pewarisan) :
Bila style tidak didefinisikan, maka akan digunakan definisi style dari induknya
<html> <head> <style type="text/css"> body {color: navy} h1 {font-family: Arial} b {text-decoration: underline} </style> </head> <body> <h1>Ini <b>Homepage</b> Saya</h1> Ini adalah homepage yang menggunakan CSS. </body> </html>
Macam-macam Selector
Class
.mhs .nama {font: bold 20 Arial}
ID
#mhs02 {color: red}
Kontekstual
h1 i {color: navy} div.mhs .alamat b {color: green}
Class Selector
p.right {text-align: right} p.center {text-align: center} <p class="right"> This paragraph will be rightaligned. </p> <p class="center"> This paragraph will be center-aligned. </p>
STMIK Asia Malang -
Class Selector
.center {text-align: center} <h1 class="center"> This heading will be center-aligned </h1> <p class="center"> This paragraph will also be center-aligned. </p>
Pseudo Class
Pseudo class dapat digunakan sebagai selector meskipun class-nya tidak terdapat di kode HTML Untuk menyatakan style yang digunakan jika suatu kondisi eksternal dikenakan pada elemen HTML (misalnya di-klik mouse) Sintaks pseudo class : selector:pseudo-class {property: value} Anchor (<A>) pseudo class :
:link :visited :hover :active :focus { { { { { { color: color: color: color: color: color: red } green } blue } purple } yellow } maroon }
Contoh :
a:link a:visited a:hover a:active a:focus a.mhs:link
Pseudo Element
Untuk menyatakan style yang digunakan terhadap suatu kondisi tipografi, bukan struktur (misalnya baris pertama)
Pseudo element :
Contoh :
p:first-letter p:first-line
Font
font-family: <fontname>
p {font-family: Arial, Verdana, "Times New Roman"}
font-size: xx-small | x-small | small | medium | large | x-large | xx-large font-size: larger | smaller font-size: <length> | <percentage>
p {font-size: large} p {font-size: smaller} p {font-size: 200px} p {font-size: 150%}
font: [<style>||<variant>||<weight>]? <size>[/<line-height>]? <family> font: caption | icon | menu | message-box | small-caption | status-bar
p {font: italic 12pt "Helvetica Nue", serif} p {font: bold italic large Palatino, serif} p {font: normal small-caps bold 120%/120% fantasy} p {font: x-large/20pt "new century schoolbook", serif} p {font: menu}
color: <color>
p {color: red} p {color: #448F2C}
p {color: rgb(255,0,0)}
p {color: rgb(100%,50%,25%)} p {color: #f25}
Text
List
list-style-type: disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-alpha | lower-latin | upper-alpha | upper-latin | none
ul {list-style-type: circle}
outside
inside
Perintah CSS
Perintah CSS lebih lengkap dapat dilihat pada link file berikut: perintah css.pdf
Latihan