STYLE SHEET
I. RINGKASAN
Setelah semua yang Anda ketahui tentang dasar pembuatan halaman web, kini tiba
saatnya untuk membuat halaman web Anda tampil lebih meyakinkan. Untuk keperluan
tersebut, Anda dapat menggunakan style sheet/CSS .
Style Sheet dapat digunakan dengan 3 cara, sesuai dengan kebutuhan anda:
1. Dengan membuat link ke file Style Sheet dari file HTML. Metode seperti ini
memungkinkan anda mengubah style sejumlah halaman web dengan hanya
mengedit satu file Style Sheet.
Contoh:
a. Anda membuat satu file dengan notepad atau teks editor lain, dan berinama,
misalkan: style.css, lalu tuliskan kode-kode css di dalam file tersebut.
h1 {color: red; }
b. Langkah kedua adalah memanggil file style.css dari semua halaman web.
Caranya dengan memasukkan kode di bawah ini, di antara tag <head> dan
</head> seperti dibawah ini.
<head>
</head>
2. Dengan menyisipkan Style Sheet pada file HTML. Metode seperti ini memungkinkan
anda mengubah style suatu halaman web dengan hanya mengedit beberapa baris
Style Sheet.
Contoh :
<head>
p {color:blue;}
</style>
</head>
<P style=”color:blue”>
Isi paragraf.
</p>
Cara ini sebaiknya hanya digunakan jika anda mau memformat suatu elemen satu kali
saja. Anda dapat menggunakan satu, dua, atau ketiga cara tersebut pada halaman web.
LATIHAN
2. Penanganan font
3. Pembuatan border
<html>
<head>
<style type="text/css">
p.borderous
{
border-style: double;
border-width: 5px 10px 1px medium;
border-color: #ff0000
#00ff00 #0000ff
rgb(250,0,255)
}
</style>
</head>
<body>
<p class="borderous">
4. Pengaturan margin
<html>
<head>
<style type="text/css">
p.margin {margin: 2cm 4cm 3cm 80px}
</style>
</head>
<body>
<p>
Yang ini adalah paragraf biasa tanpa pengaturan margin, sepertinya biasa saja.
</p>
<p class="margin">
Bandingkan dengan tampilan paragraf ini. Coba Anda kecilkan ukuran window
browser agar terlihat lebih jelas perbedaannya.
</p>
<p>
This is a paragraph
</p>
</body>
</html>
6. Menggunakan list
<html>
<head>
<style type="text/css">
ul
{
list-style: square outside url("gambarkecil.gif")
}
/*jangan lupa gambarkecil.gif harus ada*/
</style>
</head>
<body>
<p>Disini Anda menggunakan gambar berukuran kecil sebagai bullet untuk list.
Properti outside akan menyebabkan list menjadi lebih rapi bila terdiri atas item yang
berupa kalimat panjang dan window browser berukuran kecil.</p>
<ul>
<li>Kopi</li>
<li>Teh</li>
<li>Coca Cola</li>
</ul>
</body>
</html>
Class selector adalah penggabungan beberapa properties yang digunakan lebih dari
satu kali. Cara penulisan Class Selector:
.nama-class {property:value;}
taghtml.nama-class {Property:value;}
Perhatikan tanda titik di setiap awal nama Class. Jika anda ingin menggunakan class
selector di luar kode HTML anda menggunakan tag <div class=nama-class> dan di
akhiri dengan tag </div>.
.tengah {text-align:center;}
p.tengah {color:red;}
h1.kiri {color:blue;}
h1.tengah {color:black;}
III. ID Selector
ID Selector mirip dengan Class selector. Untuk membedakannya, gunakanlah ID
selector untuk memformat bagian yang hanya muncul satu kali dalam satu halaman
web, misalnya untuk memformat bagian menu / sidebar.
#nama-ID {property:value;}
taghtml#nama-ID {Property:value;}
Perhatikan tanda # di setiap awal nama ID. Jika anda ingin menggunakan class selector
di luar kode HTML anda menggunakan tag <div id=nama-ID> dan di akhiri dengan tag
</div>.
<div id="content">
body {
font-family: Georgia;
background: #eaeaea;
text-align: center;
color: #464530;
text-shadow: 0px 1px 0px #fff;
font-size: 30px;
font-weight: bold;
letter-spacing: -1px;
margin-top: 5%;
}
a, a:visited {
color: #464530;
text-decoration: none;
}
label {
font-size: 20px;
}
#content {
display: block;
width: 730px;
margin-right: auto;
margin-left: auto;
text-align: center;
}
.block {
font-size: 30px;
background: #eaeaea;
-webkit-box-shadow: inset 0px 0px 10px rgba(0,0,0, .3);
-moz-box-shadow: inset 0px 0px 10px rgba(0,0,0, .3);
box-shadow: inset 0px 0px 10px rgba(0,0,0, .3);
-webkit-border-radius: 3px;
padding: 40px 15px;
}
.cleaner {
clear: both;
}
#fly-menu, #fly-glow-menu {
margin: 1em auto 0 auto;
}
/* Membuat style */
list-style-type: none;
margin-right: .5em;
float: left;
font-size: 15px;
background: #cacaca;
padding: 10px;
cursor: pointer;
/* Membuat shadow/bayangan */
-webkit-box-shadow: inset 0px 0px 10px rgba(0,0,0, .3);
-moz-box-shadow: inset 0px 0px 10px rgba(0,0,0, .3);
box-shadow: inset 0px 0px 10px rgba(0,0,0, .3);
#fly-menu li:hover {
margin-top: -1em;
}
#fly-glow-menu li:hover {
margin-top: -1em;
background: #fff;
<html>
<head><title>Latihan Menu dengan CSS</title>
<style type="text/css">
menu{font-family:"Comic Sans MS"; font-size:12px;
display:none;
text-decoration:none;
width:150px;
}
.menu1{
background-color:#000000;
color:#FFFFFF;
text-decoration:none;
display:block;
margin: 2px;
padding: 5px;
-moz-border-radius:25px;
-webkit-border-radius:25px;
}
.menu1:hover{
color:#FFFFFF;
background-color:#0000FF;
text-decoration:none;
display:block;
}
#mm:hover, #mm:hover menu{
display:block;
}
.mu{
<html>
<head>
<title>Drop Down Menu</title>
<style type="text/css">
#place-nav {
width:960px;
height:35px;
margin:63px 0 0 0;
}
#nav {
height:35px;
}
#nav li {
height:35px;
float:left;
display:inline;
margin:0 5px;
position:relative;
font-family: Arial, verdana, serif;
z-index:1000;
}
#nav li a {
float:left;
display:inline;
height:25px;
padding:10px 8px 0 8px;
font-size:12px;
color:#9e9e9e;
font-weight:bold;
text-transform:uppercase;
text-shadow:0 0 3px #c7c7c7;
}
#nav li:hover a {
</head><body>
<div id="place-nav">
<ul id="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Artikel</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Social</a>
<ul>
<li><a href="#">Facebook</a></li>
<li><a href="#">Google</a>
<ul>
<li><a href="#">Google Wave</a></li>
<li><a href="#">Google Buzz</a></li>
<li><a href="#">Google Plus</a></li>
</ul>
</li>
<li><a href="#">Twitter</a></li>
</ul>
</li>
<li><a href="#">Portfolio</a></li>
</ul>
</div>
</body></html>
1. Dua_halaman.html
<html>
<head>
<title>2 kolom</title>
<link rel="stylesheet" href="style_kolom.css"
type="text/css" media="screen" />
<style type="text/css" media="screen">
/* <![CDATA[ */ @import url(style_kolom.css); /* ]]> */
</style>
</head>
<body>
<div id="nav">
<ul>
<li><a href="#">Contoh Link 1</a></li>
<li><a href="#">Contoh Link 2</a></li>
<li><a href="#">Contoh Link 3</a></li>
</ul>
</div>
<div id="content">
<h1>Layout dua kolom sederhana</h1>
<p><strong>Step x - bold text here...</strong> More text
here...</p>
<p>More text here...</p>
<p>More text here...</p>
<p>More text here...</p>
</div>
</body>
</html>
2. Style_kolom.css
body {margin:0px; padding:0px; font: 1em verdana, arial,
sans-serif;}
div#nav {position:absolute; left:0px; top:0px; width:150px;
padding:.5em 0 0 0; margin:22px 0 0 15px; border-top:2px
solid #069; border-bottom:1px solid #069;}
2. Style.css
*{margin:0 auto; padding:0}
body{background:#c0c0c0;
font-family:verdana;
font-size:10px; color:#4c4e55;
}
#container{width:1007px; height:1369px;
background:url('bg.jpg') no-repeat;
}
#header{height: 150px;
border: 1px solid #009900;
}
#sidebar_kiri{float:left; width:250px;
height:1000px; margin:3px 0;
padding:3px; border:1px solid #009900;
}
#sidebar_kanan{float:left; width:150px;
height:1000px; margin:3px 0;
padding: 3px; border: 1px solid #009900;
}
#footer{height:201px; border:1px solid #009900;
clear: both;
}
1. Web-colimg.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-
8859-1" />
<title>Bali Exotique Island</title>
<body>
<div id="layout">
<div id="header"></div>
<div id="kolom1">Our Services
<ul><li>Travel and Tour Package</li>
<li>Wedding Reception</li>
<li>Event Organizer</li>
<li>Adventure Trip</li>
</ul>
</div>
<div id="kolom2">Bali as you know, is the most pleased place to
visit. Bali give you an aroma of paradise on earth. as you know,
is the most pleased place to visit. Bali give you an aroma of
paradise on earth. as you know, is the most pleased place to
visit. Bali give you an aroma of paradise on earth. as you know,
is the most pleased place to visit. Bali give you an aroma of
paradise on earth. as you know, is the most pleased place to
visit. Bali give you an aroma of paradise on earth. as you know,
is the most pleased place to visit. Bali give you an aroma of
paradise on earth. as you know, is the most pleased place to
visit. Bali give you an aroma of paradise on earth. as you know,
is the most pleased place to visit. Bali give you an aroma of
paradise on earth. as you know, is the most pleased place to
visit. Bali give you an aroma of paradise on earth.
</div>
<div id="footer"></div>
</div>
</body>
</html>
2. Style.css
*{margin:0 auto; padding:2}
#layout {
height: auto;
width: 700px;
background:url('bg.jpg') no-repeat;
}
#header {
float: left;
height: 200px;
width: 700px;
background-image: url(bg3.jpg);
}
#kolom1 {
float: left;
height: auto;
width: 200px;
background-image: url(kol1.gif);
Catatan : gambar yang kita buat sesuaikan dengan nama pada CSSnya seperti:
footer.jpg
header.jpg
kolom1.jpg
kolom2.jpg
Tabel dapat kita bagi menjadi baris judul dan baris isi dengan menggunakan tag <th>
dan <tr> dan tiap cell akan menggunakan tag <td>. Selanjutnya, perlu kita ketahui
terlebih dahulu beberapa properti yang melengkapi sebuah tabel dan dapat diatur
menggunakan CSS. Properti tersebut adalah:
1. Border, misal : table, th, td{border:1px solid red;}
maka hasilnya adalah sbb :
2. Collapse Border, tabel diatas mempunyai banyak border, apabila border untuk tabel
dan cell akan kita gabung maka kita menambahkan
table {border-collapse:collapse;}
table, th, td{border: 1px solid red;}
Untuk membuat sudut lengkung (rounded corner) gunakan pengaturan css berikut :
.contoh div {
background:#0CF;
height:40px;
width:400px;
border:2px solid #F90;
-moz-border-radius:25px; /* Firefox */
border-radius:25px;
}
Hasilnya :