Selasa, 06 Desember 2016

Bab 7. CSS HTML



Css html

1.     PENGENALAN CSS
Ø  CSS = Cascading Style Sheet adalah suatu teknik penulisan kode untuk memperindah dan mempermudah dalam pengkodean HTML dengan tujuan untuk memperindah tampilan situs.
2.     SINTAKS CSS
Ø  Secara umum CSS terdiri dari 2 bagian,yaitu:
o   Selector,menunjukkan elemen yang akan diatur/diformat. Jika digunakan untuk lebih dari 1 elemen,gunakan pemisah berupa tanda koma (,).
o   Declaration,merupakan pengaturan dari selector yang dipilih.
§  Property yaitu bagian dari elemen yang akan diatur
§  Value yaitu nilai dari property element yang diatur.
3.      SELECTOR DALAM CSS
Pada CSS terdapat 3 macam selector,yaitu:

Ø  CLASS
Selector diawali dengan tanda “.” (dot). Sebuah selector class dapat digunakan lebih dari satu tag HTML. Masukkan style css dalam selector class jika terdapat 2 atau lebih elemen/tag HTML yang bisa memiliki style yang sama dalam satu halaman.
Contoh kode selector class:
.post{background-color:#cdcdcd;}

Kode HTML untuk menggunakan selector class tersebut:
<div class=”post”>.....teks....</div>
Class “.post” dapat digunakan lebih dari 1 kali pada sebuah halaman.
Ø ID
Selector id diawali dengan tanda “#”. Kebalikan dari selector class,selector id boleh digunakan sekali pada satu halaman.
Contoh kode selector id:
#header{backgorund-color:silver;padding:5px;}

Kode HTML untuk menggunakan selector id:
<div id=”header”> teks contoh </div>


Ø TAG HTML
Selector tag HTML tidak memerlukan tanda awalan apapun. Berbeda dengan selector ID dan selector class,selector HTML akan mempengaruhi tag HTML yang diberi style.
Contoh kodenya :
p {font-family:Arial;font-size:10pt;}
kode diatas akan membuat semua tag <p> {paragraf} agar ditampilkan menggunakan font Arial dengan ukuran 10pt (point).

4.     PROPERTY YANG DAPAT DIATUR CSS
Property yang dapat diatur menggunakan CSS :
Type
Property
ð  Font
o   Font
o   Font-family
o   Font-size
o   Font-size-adjust
o   Font-stretch
o   Font-style
o   Font-variant
o   Font-weight
ð  Text
*      Color
*      Direction
*      Color
*      Letter-spacing
*      Text-align
*      Text-decoration
*      Text-indent
*      Text-shadow
*      Text-transform
*      Unicode-bidi
*      White-space
*      Word-spacing
ð  Background
v  Background
v  Background-attachment
v  Background-color
v  Background-image
v  Background-position
v  Background-repeat
ð  Border
Ø  Border
Ø  Border-color
Ø  Border-style
Ø  Border-width
Ø  Border-bottom
Ø  Border-bottom-color
Ø  Border-bottom-style
Ø  Border-bottom-width
Ø  Border-left
Ø  Border-left-color
Ø  Border-left-style
Ø  Border-left-width
Ø  Border-right
Ø  Border-right-color
Ø  Border-right-style
Ø  Border-left-width
Ø  Border-top
Ø  Border-top-color
Ø  Border-top-style
Ø  Border-top-width
ð  Margin
ü  Margin
ü  Margin-bottom
ü  Margin-left
ü  Margin-right
ü  Margin-top
ð  Padding
§  Padding
§  Padding-bottom
§  Padding-left
§  Padding-right
§  Padding-top
ð  Dimension
o Height
o Line-height
o Max-height
o Max-width
o Min-height
o Min-width
o Width
ð  Position
Ø  Bottom
Ø  Clip
Ø  Left
Ø  Overflow
Ø  Right
Ø  Top
Ø  Vertical-align
Ø  Z-indexs
ð  Outline
i.                    Outline
ii.                  Outline-color
iii.                Outline-style
iv.                Outline-width
ð  Table
ü  Border-collapse
ü  Border-spacing
ü  Border-side
ü  Empty-cells
ü  Table-layout
ð  List and Marker
·         List-style
·         List-style-image
·         List-style-position
·         List-style-type
·         Marker-offset
ð  Generated Content
*      Content
*      Counter-increment
*      Counter-reset
*      Quotes
ð  Classification
v  Clear
v  Cursor
v  Display
v  Float
v  Position
v  visibility


5.    MENAMBAHKAN CSS PADA DOKUMEN WEB
Ada 3 cara menambahkan CSS pada dokumen web,yaitu:
1.      Dengan membuat link dari dokumen HTML ke file CSS.\
Syarat utamanya adalah kita memiliki file berekstensi “.css”. Metode ini sering disebut disebut juga Eksternal Style Sheet. Bentuknya :
<link rel=”stylesheet” type=”text/css”
href=”css_files.css”>
Baris diatas biasanya diletakkan didalam elemen <head>.
Ada beberapa atribut yang dapat dibawa oleh elemen link,yaitu :
Ø  Rel
Merupakan atribut yang dibutuhkan dan mengatur hubungan antara dokumen yang memuat <link> dengan dokumen tujuan. Value yang dibutuhkan untuk bekerja dengan style sheet adalah stylesheet.
 rel=”stylesheet”
Ø  Type
Menjelaskan tipe dokumen yang akan dihubungkan. Pada kasus ini,kita akan menghubungkan dengan CSS style sheet. Maka value dari type yang dibutuhkan adalah text/css.
type=”text/css”
Ø  Href
Digunakan untuk mengatur URL dari dokumen yang akan dihubungkan.
href=”..../stylesheets/interface.css”
Ø  Hreflang
Digunakan untuk mengatur sumber bahasa penulisan
hreflang=”en-US”
Ø  Media
Digunakan untuk mendefenisikan media output yang miliki untuk digunakan bersama dokumen.
media=”screen”
beberapa value yang dapat digunakan untuk atribut media adalah :
Value
Fungsi
Screen
Layar komputer tanpa halaman (seperti komputer desktop dan laptop)
tty
Media dengan karakter grid,seperti teletype,terminal atau peralatan portable dengan kemampuan tampilan yang terbatas.
tv
Televisi dengan resolusi rendah,layar warna dan kemampuan untuk menggulung dokumen kebawah yan terbatas.
print
Dokument cetak,yang kadang-kadangditujukan sebagai pages media (dan mode pre-view dokumen didalam layar).
project
Proyektor
handheld
Peralatan handheld,yang sering memiliki layar kecil,untuk grafik bitmap,dqan memiliki bandwidth yang terbatas.
braille
Peralatan umpan balik tulisan braille.
embossed
Pencetak halaman braille.
aural
Synthesizer suara.
all
Cocok untuk semua peralatan.

2.      Dengan menyisipkan kode CSS ke dokumen HTML.

3.      Dengan mengisipkan secara inline pada tag HTML.

BAB 8. CSS LANJUTAN



BAB 8 CSS LANJUTAN
1.      PENGATURAN LINK DENGAN CSS
Beberapa property yang sering digunakan untuk link adalah :
*      Color : mengganti warna link
*      Background : memberi warna sorotan
*      Text-decoration : biasanya untuk membuat link bergaris bawah (underline) atau tidak,tetapi dapat pula digunakan untuk membuat link bergaris silang,berkedip atau bergaris tengah.

Ada  4 pseudo-classes untuk yaitu,yaitu :
v  Link : style untuk link secara umum (biasa).
v  Visited : style untuk style yang telah dikunjungi.
v  Hover : style untuk link ketika didekati kursor.
v  Active : style untuk link yang sedang aktif.

Berikut adalah contoh CSS untuk link :
Body {background-color : #ffffff; }
a {
font-family : arial,verdana,sans-seri
font-size : 12px;
font-wight : bold; }
a : link {
color : #0000ff;
text-decoration : none; }
a: visited {
color : #333399;
text-decoration : none; }
a : link : hover  {
background-color :#e9e9e9;
text-decoration : underline; }
a :active {
color : #0033ff;
text-decoration : underline; }

2.      PENGATURAN BACKGORUND DENGAN CSS
Berikut adalah beberapa property yang dapat digunakan untuk melakukan pengaturan background :
Property
Fungsi
Background-color
Digunakan untuk mengatur warna latar. Contoh :

body{background-color : #cccccc ; color : #000000;}
b {background-color : #FF0000; color: #FFFFFF;}
p {backgorund-color : rgb (255,255,255);}
Background-image
Menggunakan gambar sebagai latar. Contoh :

body {
background-image :
url (“image/background.gif”) ;
background-color : #cccccc;}
Background-repeat
Mengatur apakah gambar latar diulang atau tidak.
Ada 4 macam perulangan gambar untuk background :
Ø  Repeat  : gambar diulang memenuhi halaman.
Ø  Repeat-x : gambar diulang secara vertikal.
Ø  Repeat-y : gambar diulang secara horizontal.
Ø  No-repeat : gambar hanya ditampilkan sekali.

body {
background-image :
url (“image/background_small.gif”);
background-repeat : repeat-y;}
Background-attachment
Menetapkan gambar latar pada letak tertentu di halaman dan apakah gambar tersebut tetap pada letaknya jika halaman digeser kebawah. Ada dua value dari property ini :
ü  Fixed : gambar tidak akan bergerak walau halaman digeser keatas atau kebawah.
ü  Scroll : gambar bergerak bersama halaman.

body {
 background-image :
url (“images/background_small.hif”);
background-attachment:fixed;}
Background-position
Mengatur dimana gambar latar akan diletakkan. Ada beberapa value untuk property ini :
*      X% y% : persentasi dimana x ( horizontal) dan y (vertikal)
*      X y : nilai tetap x dan y dalam pixel.
*      Left : gambar disebelah kiri halaman atau elemen.
*      Center : gambar ditengah halaman atau elemen.
*      Right : gambar berada di sebelah kanan halaman atau elemen.
*      Top : gambar disebelah atas halaman atau elemen.
*      Bottom : gambar disebelah bawah atau elemen.

body {
background-image :
url (“images/background_small.gif”);
background-position : 50% 20%;}
Background
Memungkinkan untuk melakukan pengaturan dari semua property.

body {background : #cc66ff;
url(“image/background_small.gif”) fixed
non-repeat center ;}
                                                   
(color.html)
Body {background-color : #ffffff; }
a {
font-family : arial,verdana,sans-seri
font-size : 12px;
font-wight : bold; }
a : link {
color : #0000ff;
text-decoration : none; }
a: visited {
color : #333399;
text-decoration : none; }
a : link : hover  {
background-color :#e9e9e9;
text-decoration : underline; }
a :active {
color : #0033ff;
text-decoration : underline; }


(link.html)
<html>
<head>
<title>CSS Example</title>
<link rel="stylesheet" type="text/css"
href="link.css"/>
</head>
<body>
<h1>Link Style</h1>
<p>This example contains some links,which you should
play with to see how they behave:</p>
<ul>
<li>The <a href="http://www.wrox.com/">Wrox Website</a> is the home of the XHTML and CSS recomendation.</li>
<li>The <a href="http://www.google.com/">Google Website</a> is a popular search tool that will help you
find answer to any question you  have.</li>
</ul>
</body>
</html>

link.css
body{background-color:#ffffff;}
a {
font-family:arial,verdana,sans-serif;
font-size:12px;
font-weight:bold;}
a:link {
color:#0000ff;
text-decoration:none;}
a:visited{
color:#333399;
text-decoration:none;}
a:active{
color:#0033ff;
text-decoration:underline;}
a:link:hover{
background-color:#e9e9e9;
text-decoration:underline;}
 

(List.html)
<html>
<head>
<title>CSS Example</title>
<link rel="stylesheet" type="text/css"
href="list.css"/>
</head>
<body>
<ul>
<li> This example illustrates using an image for a bullet point.</li>
<li> This example illustrates using an image for a bullet point.</li>
<li> This example illustrates using an image for a bullet point.</li>
</ul>
</body>
</html>

list.css
body {background-color: #ffffff;}
ul{list-style-image: url("image/bulletpoint.gif");}
li {marker-offset:20px;}
 

table.html
<html>
<head>
<title> CSS Example</title>
<link rel="stylesheet" type="text/css"
href="table.css"/>
</head>
<body>
<table border="2">
<caption><b>Font properties</caption>
<tr>
<th>Property</th>
<th>Purpose</th>
</tr>
<tr>
<td class="code">font-family</td>
<td>Specifies the size font use. </td>
</tr>
<td class="code">font-size</td>
<td>Specifies the size of font use. </td>
</tr>
<tr>
<td class="code">font-style</td>
<td>Specifies whether the font sould be normal,
italic, or oblique. </td>
</tr>
<td class="code">font-wight</td>
<td>Specifies whether the font sould be normal,
bold,bolder,or lighter. </td>
</tr>
</table>
</body>
</html>

table.css
body {
color:#000000;
h1 {font-size:18pt;}
p {font-size:12pt;}
table{
background-color:#efefef;
width:350px;
border-style:solid;
border-width:1px;
border-color:#999999;
font-family:arial,verdana,sans-serif;}

caption {
font-weight:bold;
text-align:left;
border-style:sclid;border-widht:1px;border-color:#666666;}
th{
height:50px;
font-weight:bold;
text-align:left;
background-color:#cccccc}
td,th{padding:5px;}
td.code{
width:50px;
font-family:courier,courier-new,serif;
font-weight:bold;
text-align:right;
vertical-alihn:top;}
 
 
table2.html
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
xml:lang="en">
<head>
<title>Table styles</title>
<link rel="stylesheet" type="text/css"
href="table2.css"/>
</head>
<body>
<table border="2">
<tr>
<th>Quantity</th>
<th>Ingredient</th>
</tr>
<tr class="odd">
<td>3</td>
<td>Eggs</td>
</tr>
<td>100ml</td>
<td>Milk</td>
</tr>
<tr class="odd">
<td>200g</td>
<td>Spinach</td>
</tr>
<tr>
<td>1 pinch</td>
<td>Cinnanom</td>
</tr>
</table>
</body>
</html>

table2.css
body {
 background-color:#ffffff;
 font-family:arial, verdana, sans-serif;
 font-size : 14px;}
 table {
 border-style:solid;
 border-width:1px;
 border-color:#666666;}
 th {
 color:#ffffff;
 background-color:#999999;
 font-weight:bold;
 border:none;
 padding:4px;}
 tr {background-color :#cccccc;}
 tr.odd {background-color:#efefef;}
 td {
 color:#000000;
 padding:2px;}

Lanjutan Bab 9

<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8">
<link href="layout2kolom.css" rel="stylesheet"
type="text/css"/>
<title>Tutorial CSS Layout</title>
</head>
<body>
<div id="wrapper">
<div id="header">
<a
href="http://localhost/web_css"><h1>Tutorial CSS
Layout</h1></a>
</div>
<div id="sidebar">
Menu
<ul class="menu">
<li><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Contact Us</a></li>
<li><a href="#">About Us</a></li>
</ul>
</div>
<div id="content">
<h2>Selamat Datang</h2>
<p>Lorem ipsum dolor sit amet,
consectetur adipiscing elit.Donec vitae semper arcu.
</p>
</div>
<div id="footer">
<p>Copyright dan & copy : 2010 by Cheyus </p>
</div>
</div>
</body>
</html>
(ini adalah scrip layout2kolom.html)

*{
font-size: 12px;
font-family: sans-serif;
}
body {
background: #efefef;
margin: 0;
}
a {
 text-decoration: none;
 color: black;
}
a: hover{
 text-decoration: underline;
 color: #0000cc;
}
h1 {
 font-size: 36px;
 margin: 0;
}
h2 {
 font-size: 24px;
}
#wrapper {
 width: 950px;
 margin: auto;
 background: #fff;
}
#header {
height: 150px;
background: #cdf;
}

#sidebar {
 float: left;
 width: 200px;
 padding: 5px;
}
#content {
 float: left;
 width: 700px;
 padding: 5px 5px 5px 20px;
 border-left: 1px solid #ccc;
}
#footer {
 clear: both;
 background: #bbb;
}
#footer p{
 text-align: center;
 padding: 20px;
 color: #fff;
 font-size: 10px;
 font-weight: 900;
}
(layout.css) 

LAYOUT.CSS (bab 9)

/* INDEX :
1. WRAPPER
2. READER
3. MENU
4. SIDEBAR
5. CONTENT
6. FOOTER
*/
body{
background-color:#FFC;
font-family:"calibri"
}
/* 1. WRAPPER
-----------------------------*/
#wrapper {
width: 850px;
margin: 15px auto;
height : auto;
padding:20px;
background-color: #FFF
box-shadow: 0px 0px 20px #F60;
-moz-box-shadow :0px 0px 20px #F60;
-webkit-box-shadow :0px 0px 20px #F60;
border-radius: 17px;
-moz-border-radius: 17px;
-webkit-border-radius: 17px;
}
/* 2. HEADER
------------------------------*/
#header{
 width: 850px;
 height: 70px;
 border: 1px solid #CCC;
 margin-bottom: 7px;
 text-align: center;
}
/* 3. MENU
------------------------------*/
#menu{
 width: 850px;
 height: 27px;
 margin-bottom: 7px;
 border: 1px solid #FFF;
 background-color: #CCC;
 font-size: 17px;
 border-radius: 5px;
 -moz-border-radius: 5px;
 -webkit-border-radius: 5px;
}
#menu ul {
 margin: 4px 4px 4px 7px;
 padding: 0px;
 list-style: none;
}
#menu li{
 margin: 10px;
 padding: 0px;
 display: inline;
}
#menu a{
 padding: 6px 6px 6px 6px;
 text-decoration: none;
}
#menu a:hover{
 padding: 5px 5px 2px 5px;
 text-decoration: none;
 color: #FFF;
 background: #FF9000;
}
/* 4. SIDEBAR
----------------------------------*/
#sidebar {
 float: right;
 width: 300px;
 height: 290px;
 border: 1px solid #CCC;
 margin-bottom: 7px;
 text-align: center;
}
/* 5.CONTENT
-----------------------------------*/
#content{
 width: 538px;
 height: 290px;
 margin-bottom: 2px;
 border: 1px solid #CCC;
 margin-bottom: 7px;
}
#content img {
 border-radius: 17px;
 -moz-border-radius: 17px;
 -webkit-border-radius: 17px;
 box-shadow: 0px 0px 10px #CCC;
 -moz-box-shadow: 0px 0px 10px #CCC;
 -webkit-box-shadow: 0px 0px 10px #CCC;
 padding: 2px; margin-right: 10px;
 float:left;
}
/* 6. FOOTER
------------------------------------*/
#footer{
 width: 850px;
 height: 20px;
 padding-top: 0px;
 border: 1px solid #CCC;
 text-align: center;
 background-color: #CCC;
 clear: both;
 border-radius: 3px;
 -moz-border-radius: 3px;
 -webkit-border-radius: 3px;
 }
 
Ini adalah kode/scrip CSS dari layout.html  yang telah diposting sebelumnya...

INDEX.HTML (bsb 9)

<html>
<head>
<title>Layout WEB/BLOG</title>
<link rel="stylesheet" href="layout.css"
type="text/css"/>
</head>
<body>
<div id="wrapper">
<!---------------#header-------------->
<div id="header">
<h1>Header</h1>
</div>
<!--------------#menu----------------->
<div id="menu">
<ul>
<li><a href="index.php">Beranda</a></li>
<li><a href="#">Profil</a></li>
<li><a href="#">Kontak</a></li>
<li><a href="#">Galeri Foto</a></li>
</ul>
</div>
<!-------------#sidebar--------------->
<div id="sidebar">
<div class="previous">Sidebar</div>
</div>
<!-------------#content--------------->
<div id="content">
<img src="image/IMG_20160914_092542.jpg" width="144" height="144" />
<br>Bagian ini silahkan isi dengan posing anda.
Web/Blog yang dinamis selalu menyisipkan kode PHP pada bagian ini,
agar
data-data dapat dengan mudah untuk diubah dan diperbanyak.
</div>
<!-------------#footer--------------->
<div id="footer">
Copyright & copy ; 2012 by : <a
href="#">esdua.web</a></div>
</div>

</div>
</body>
</html>