Input:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightblue;
}
h1 {
color: white;
text-align: center;
}
p{
font-family: verdana;
font-size: 20px;
}
</style>
</head>
<body>
</body>
</html>
Output :
CSS Syntax
Input:
<!DOCTYPE html>
<html>
<head>
<style>
p{
color: red;
text-align: center;
}
</style>
</head>
<body>
<p>Hello World!</p>
<p>These paragraphs are styled with CSS.</p>
</body>
</html>
Output :
CSS Comments
Input:
<!DOCTYPE html>
<html>
<head>
<style>
p{
color: red;
/* This is a single-line comment */
text-align: center;
}
/* This is
a multi-line
comment */
</style>
</head>
<body>
<p>Hello World!</p>
<p>This paragraph is styled with CSS.</p>
<p>CSS comments are not shown in the output.</p>
</body>
</html>
Output :
Analisa : CSS juga bisa menggunakan komentar dan tidak akan ditampilkan.
<!DOCTYPE html>
<html>
<head>
<style>
p{
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<style>
#para1 {
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
Output :
Analisa : dengan menggunakan #para1 maka akan langsung spesifik dan yang lainnya tidak terpengaruh
<!DOCTYPE html>
<html>
<head>
<style>
.center {
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
Output :
Analisa : Dengan menggunakan <h1> dan <p> dengan menulis class maka akan mengikuti aturannya
Input:
<!DOCTYPE html>
<html>
<head>
<style>
p.center {
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<style>
p.center {
text-align: center;
color: red;
}
p.large {
font-size: 300%;
}
</style>
</head>
<body>
</body>
</html>
Output :
Analisa : dengan menambahkan p.large kita bisa mengatur syntax nya menjadi besar
<!DOCTYPE html>
<html>
<head>
<style>
*{
text-align: center;
color: blue;
}
</style>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<style>
h1, h2, p {
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<h2>Smaller heading!</h2>
<p>This is a paragraph.</p>
</body>
</html>
Output :
Analisa : dengan memilih kode yang diinginkan , maka akan mengikuti syntax yang diinginkan
CSS HOW-TO
External CSS
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Analisis: Dengan external style sheet, Anda dapat mengubah tampilan seluruh situs web dengan
mengubah hanya satu file. Setiap halaman HTML harus menyertakan referensi ke file style sheet
eksternal di dalam elemen <link>, di dalam bagian kepala HTML. Gaya eksternal ditentukan dalam
elemen <link>, di dalam bagian <head> dari halaman HTML:
Internal CSS
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: linen;
h1 {
color: maroon;
margin-left: 40px;
</style>
</head>
<body>
</body>
</html>
Analisis: Internal style sheet dapat digunakan jika satu halaman HTML tunggal memiliki gaya yang unik.
Gaya internal didefinisikan di dalam elemen <style>, di dalam bagian kepala dari halaman HTML:
Inline CSS
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Analisis: Gaya inline dapat digunakan untuk menerapkan gaya unik untuk elemen tunggal. Untuk
menggunakan gaya inline, tambahkan atribut gaya ke elemen yang relevan. Atribut style dapat berisi
properti CSS apa pun.
Multiple Style Sheets
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: orange;
</style>
</head>
<body>
</body>
</html>
Analisis: Jika beberapa properti telah ditentukan untuk elemen yang sama di style sheet yang berbeda,
nilai dari sheet style read terakhir akan digunakan.
Cascading Order
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
</body>
</html>
Analisis; Jika ada lebih dari satu gaya yang digunakan, maka page akan memproritaskan gaya inline
terlebih dahulu. Lalu gaya eksternal dan internal, dan yang terakhir gaya default browser.
CSS COLORS
<html>
<body>
<h1 style="background-color:Tomato;">Tomato</h1>
<h1 style="background-color:Orange;">Orange</h1>
<h1 style="background-
color:DodgerBlue;">DodgerBlue</h1>
<h1 style="background-
color:MediumSeaGreen;">MediumSeaGreen</h1>
<h1 style="background-color:Gray;">Gray</h1>
<h1 style="background-color:SlateBlue;">SlateBlue</h1>
<h1 style="background-color:Violet;">Violet</h1>
<h1 style="background-color:LightGray;">LightGray</h1>
</body>
</html>
Analisis: Dalam CSS, warna dapat ditentukan dengan menggunakan nama warna. Nama warna yang bisa
digunakan yaitu merah tomat, jingga, biru muda, hijau laut, abu-abu, biru, violet, dan abu-abu muda.
CSS Background Color
<!DOCTYPE html>
<html>
<body>
<p style="background-color:Tomato;">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl
ut aliquip ex ea commodo consequat.
</p>
</body>
</html>
Analisis: Anda dapat mengatur warna latar belakang untuk elemen HTML. Warna yang digunakan bisa
menggunakan nama warna langsung.
CSS Text Color
<!DOCTYPE html>
<html>
<body>
<p style="color:DodgerBlue;">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed
diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p style="color:MediumSeaGreen;">Ut wisi enim ad minim veniam, quis nostrud exerci tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</body>
</html>
Analisis: Anda dapat mengatur warna. Warna yang digunakan bisa menggunakan nama warna langsung.
CSS Border Color
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Analisis: Anda dapat mengatur warna border. Warna yang digunakan bisa menggunakan nama warna
langsung.
CSS Color Values
<!DOCTYPE html>
<html>
<body>
<h1 style="background-color:#ff6347;">#ff6347</h1>
<p>Warna ini sama seperti warna "merah tomat", tapi 50% transparan:</p>
</body>
</html>
Analisis: Dalam CSS, warna juga dapat ditentukan menggunakan nilai RGB (red green blue), nilai HEX
(#rrggbb), nilai HSL (hue, saturation, lightness), nilai RGBA(RGB + Alpha), dan nilai HSLA (HSL +
Alpha). Hasil yang dikeluarkan bisa juga sama dengan nama warna.
CSS BACKGROUNDS
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightblue;
</style>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
div {
background-color: lightblue;
}
p {
background-color: purple;
}
</style>
</head>
<body>
</body>
</html>
<h1>Hello World!</h1>
</body>
</html>
<h1>Hello World!</h1>
<p>This text is not easy to read on this background image.</p>
</body>
</html>
<h1>Hello World!</h1>
<p>Strange background image...</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("gradient_bg.png");
background-repeat: repeat-x;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>Here, a background image is repeated only horizontally!</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>W3Schools background image example.</p>
<p>The background image is only showing once, but it is disturbing the
reader!</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
margin-right: 200px;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>W3Schools background no-repeat, set position example.</p>
<p>Now the background image is only shown once, and positioned away from the
text.</p>
<p>In this example we have also added a margin on the right side, so the
background image will never disturb the text.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
margin-right: 200px;
background-attachment: fixed;
}
</style>
</head>
<body>
<!DOCTYPE html>
<html>
<head>
<style>
p.dotted {border-style: dotted;}
p.dashed {border-style: dashed;}
p.solid {border-style: solid;}
p.double {border-style: double;}
p.groove {border-style: groove;}
p.ridge {border-style: ridge;}
p.inset {border-style: inset;}
p.outset {border-style: outset;}
p.none {border-style: none;}
p.hidden {border-style: hidden;}
p.mix {border-style: dotted dashed solid double;}
</style>
</head>
<body>
Output :
Analisa : dengan bermacam macam jenis border, kita bisa memakainya dengan memanggil border
tersebut
CSS Margins
Margin - Individual Sides
Input:
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 1px solid black;
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
background-color: lightblue;
}
</style>
</head>
<body>
<div>This div element has a top margin of 100px, a right margin of 150px, a bottom margin of 100px,
and a left margin of 80px.</div>
</body>
</html>
Output :
Analisa : kita juga bisa mengatur margin sesuai dengan apa yang kita inginkan
Margin - Shorthand Property
Input:
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 1px solid black;
margin: 25px 50px 75px 100px;
background-color: lightblue;
}
</style>
</head>
<body>
<div>This div element has a top margin of 25px, a right margin of 50px, a bottom margin of 75px, and a
left margin of 100px.</div>
<hr>
</body>
</html>
Output :
Analisa : kita juga bisa mengatur bottom margin sesuai apa yang kita inputkan
Input:
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 1px solid black;
margin: 25px 50px 75px;
background-color: lightblue;
}
</style>
</head>
<body>
<div>This div element has a top margin of 25px, a right and left margin of 50px, and a bottom margin of
75px.</div>
<hr>
</body>
</html>
Output :
Input:
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 1px solid black;
margin: 25px 50px;
background-color: lightblue;
}
</style>
</head>
<body>
<div>This div element has a top and bottom margin of 25px, and a right and left margin of 50px.</div>
<hr>
</body>
</html>
Output :
Input:
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 1px solid black;
margin: 25px;
background-color: lightblue;
}
</style>
</head>
<body>
<div>This div element has a top, bottom, left, and right margin of 25px.</div>
<hr>
</body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<style>
div {
width:300px;
margin: auto;
border: 1px solid red;
}
</style>
</head>
<body>
<h2>Use of margin:auto</h2>
<p>You can set the margin property to auto to horizontally center the element within its container. The
element will then take up the specified width, and the remaining space will be split equally between the
left and right margins:</p>
<div>
This div will be horizontally centered because it has margin: auto;
</div>
</body>
</html>
Output :
Analisa : Kita juga bisa mengatur ukuran margin dengan ukuran auto
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 1px solid red;
margin-left: 100px;
}
p.ex1 {
margin-left: inherit;
}
</style>
</head>
<body>
<div>
<p class="ex1">This paragraph has an inherited left margin (from the div element).</p>
</div>
</body>
</html>
Output :
Analisa : kita bisa memakai inherit value agar otomatis menjadi left margin
Margin Collapse
Input:
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
margin: 0 0 50px 0;
}
h2 {
margin: 20px 0 0 0;
}
</style>
</head>
<body>
<p>In this example the h1 element has a bottom margin of 50px and the h2 element has a top margin of
20px. Then, the vertical margin between h1 and h2 should have been 70px (50px + 20px). However, due
to margin collapse, the actual margin ends up being 50px.</p>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
</body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<style>
div {
padding: 70px;
border: 1px solid #4CAF50;
}
</style>
</head>
<body>
</body>
</html>
Output :
Analisa : CSS juga bisa menginput padding dengan ukuran ynag ditentukan
</body>
</html>
Output :
</body>
</html>
Output :
Input :
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 1px solid black;
padding: 25px 50px 75px;
background-color: lightblue;
}
</style>
</head>
<body>
</body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 1px solid black;
padding: 25px 50px;
background-color: lightblue;
}
</style>
</head>
<body>
</body>
</html>
Output :
</body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<style>
div.ex1 {
width: 300px;
background-color: yellow;
}
div.ex2 {
width: 300px;
padding: 25px;
background-color: lightblue;
}
</style>
</head>
<body>
</body>
</html>
Output :
Analisa :
Kita bisa menggunnakan padding dengan element width
Input :
<!DOCTYPE html>
<html>
<head>
<style>
div.ex1 {
width: 300px;
background-color: yellow;
}
div.ex2 {
width: 300px;
padding: 25px;
box-sizing: border-box;
background-color: lightblue;
}
</style>
</head>
<body>
</body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<style>
div {
height: 200px;
width: 50%;
background-color: powderblue;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<style>
div {
height: 100px;
width: 500px;
background-color: powderblue;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
Output :
Setting max-width
Input:
<!DOCTYPE html>
<html>
<head>
<style>
div {
max-width: 500px;
height: 100px;
background-color: powderblue;
}
</style>
</head>
<body>
</body>
</html>
Output :
Analisa : kita juga bisa mengatur width sampai max yang kita tentukan
</body>
</html>
Output :
Analisa :
Pada CSS Box Model, konsep dimana setiap element yang terdapat pada halaman web
diproses sebagai kotak (box). Masing-masing HTML ini terdiri dari 4 lapisan, yaitu
konten (isi), padding, border, dan margin. Keempat lapisan inilah yang membangun
CSS Box Model.
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 320px;
padding: 10px;
border: 5px solid gray;
margin: 0;
}
</style>
</head>
<body>
<img
src="file:///C:/Users/NURHIDAYAH/Downloads/download.jpg"
width="350" height="263" alt="mawar">
<div>The picture above is 350px wide. The total width of
this element is also 350px.</div>
</body>
</html>
Output :
Analisa :
Fungsi width and heigith pada CSS Box Model adalah untuk mengatur lebar dan tinggi
area konten.
CSS Outline
CSS Outline
Listing program
<!DOCTYPE html>
<html>
<head>
<style>
p {outline-color:green;}
</style>
</head>
<body>
Analisa
Untuk menentukan pola bingkai yang diinginkan input <p class =”(pola yang diinginkan)
<!DOCTYPE html>
<html>
<head>
<style>
p.ex1 {
outline-style: solid;
outline-color: red;
p.ex2 {
outline-style: double;
Output :
Analisa :
Untuk memberikan warna maka input p.ex { , lalu bagian apa yang akan diberi warna: (pilihan warna).
Input :
<!DOCTYPE html>
<html>
<head>
<style>
p.ex1 {
outline-style: solid;
outline-color: invert;
</style>
</head>
<body>
<h2>PENS adalah</h2>
</body>
</html>
Output :
Analisa :
Untuk memberikan warna maka input p.ex { , lalu bagian apa yang akan diberi warna: (pilihan warna).
Input :
<!DOCTYPE html>
<html>
<head>
<style>
p.ex1 {
outline-style: solid;
outline-color: invert;
</style>
</head>
<body>
<h2>Using outline-color:invert</h2>
</body>
</html>
Output :
Analisa :
<!DOCTYPE html>
<html>
<head>
<style>
p.ex1 {
outline-style: solid;
outline-color: red;
outline-width: thin;
p.ex2 {
outline-style: solid;
outline-color: red;
outline-width: medium;
}
p.ex3 {
outline-style: solid;
outline-color: red;
outline-width: thick;
p.ex4 {
outline-style: solid;
outline-color: red;
outline-width: 4px;
}</style>
</head>
<body>
</body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<style>
p{
margin: 30px;
outline-offset: 15px;
</style>
</head>
<body>
</body>
</html>
Output :
Input:
<!DOCTYPE html>
<html>
<head>
<style>
p{
margin: 30px;
background:yellow;
outline-offset: 15px;
</style>
</head>
<body>
</body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<style>
.center{
margin: auto;
width: 60%;
border: 3px solid #73AD21;
padding: 10px;
}
</style>
</head>
<body>
<div class="center">
<p><b>Note: </b>Using margin: auto
will not work in IE8, unless a
!DOCTYPE is declared.</p>
</div>
</body>
</html>
Output
Penjelasan
Untuk merapikan element berada di tengah
<h2>Center Text</h2>
<div class="center">
<p>This text is centered.</p>
</div>
</body>
</html>
Output
Penjelasan
Untuk membuat teks ditengah.
CSS Align Center Image
Code
<!DOCTYPE html>
<html>
<head>
<style>
img {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<h2>Center an Image</h2>
<p>To center an image, set left and right margin to auto, and make it into a block element.</p>
<img src="C:\Users\ASUS\Desktop\paris.jpg" alt="Paris" style="width:40%">
</body>
</html>
Output
Penjelasan
Untuk membuat gambar berada di tengah.
CSS Left & Right Position
Code
<!DOCTYPE html>
<html>
<head>
<style>
.right {
position: absolute;
right: 0px;
width: 300px;
border: 3px solid #73AD21;
padding: 10px;
}
</style>
</head>
<body>
<h2>Right Align</h2>
<p>An example of how to right align elements with the position property:</p>
<div class="right">
<p>In my younger and more vulnerable years my father gave me some advice that I've been turning
over in my mind ever since.</p>
</div>
</body>
</html>
Output
Penjelasan
Untuk memosisikan div elemen di kanan atau kiri
CSS Left & Right Float
Code
!DOCTYPE html>
<html>
<head>
<style>
.right {
float: right;
width: 300px;
border: 3px solid #73AD21;
padding: 10px;
}
</style>
</head>
<body>
<h2>Right Align</h2>
<p>An example of how to right align elements with the float property:</p>
<div class="right">
<p>In my younger and more vulnerable years my father gave me some advice that I've been turning
over in my mind ever since.</p>
</div>
</body>
</html>
Output
Penjelasan
Untuk memosisikan div elemen di kanan/kiri dengan float
CSS The clearfix hack
Code
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 3px solid #4CAF50;
padding: 5px;
}
.img1 {
float: right;
}
.clearfix {
overflow: auto;
}
.img2 {
float: right;
}
</style>
</head>
<body>
<p>In this example, the image is taller than the element containing it, and it is floated, so it
overflows outside of its container:</p>
<div>
<img class="img1" src="C:\Users\ASUS\Desktop\paris.jpg" alt="Paris" width="170" height="170">
Disamping ini adalah gambar dari Paris. Paris terletak di Perancis, dan merupakan sebuah kota yang
indah.
</div>
<p style="clear:right">Add a clearfix class with overflow: auto; to the containing element, to fix this
problem:</p>
<div class="clearfix">
<img class="img2" src="C:\Users\ASUS\Desktop\paris.jpg" alt="Paris" width="170" height="170">
Disamping ini adalah gambar dari Paris. Paris terletak di Perancis, dan merupakan sebuah kota yang
indah.
</div>
</body>
</html>
Output
Penjelasan
Untuk memperbaiki elemen yang melebihi dari yang ditentukan.
CSS Center Vertically Padding
Code
<!DOCTYPE html>
<html>
<head>
<style>
.center {
padding: 70px 0;
border: 3px solid green;
}
</style>
</head>
<body>
<h2>Center Vertically</h2>
<p>In this example, we use the padding property to center the div element vertically:</p>
<div class="center">
<p>I am vertically centered.</p>
</div>
</body>
</html>
Output
Penjelasan
Untuk memosisikan di tengah dengan padding
CSS Center Vertically dengan Line Height
Code
<!DOCTYPE html>
<html>
<head>
<style>
.center {
line-height: 200px;
height: 200px;
border: 3px solid green;
text-align: center;
}
.center p {
line-height: 1.5;
display: inline-block;
vertical-align: middle;
}
</style>
</head>
<body>
<h2>Centering</h2>
<p>In this example, we use the line-height property with a value that is equal to the height property
to center the div element:</p>
<div class="center">
<p>I am vertically and horizontally centered.</p>
</div>
</body>
</html>
Output
Penjelasan
Memosisikan div elemen dengan ketinggian garis.
CSS Center Vertically using Transform&Position
Code
<!DOCTYPE html>
<html>
<head>
<style>
.center {
height: 200px;
position: relative;
border: 3px solid green;
}
.center p {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<h2>Centering</h2>
<p>In this example, we use positioning and the transform property to vertically and horizontally
center the div element:</p>
<div class="center">
<p>I am vertically and horizontally centered.</p>
</div>
<p>Note: The transform property is not supported in IE8 and earlier versions.</p>
</body>
</html>
Output
Penjelasan
Memosisikan div elemen dengan mentransformasikannya secara horizontal dan vertical
CSS Box Model
Code
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color: lightgrey;
width: 300px;
border: 15px solid red;
padding: 50px;
margin: 20px;
}
</style>
</head>
<body>
<p>The CSS box model is essentially a box that wraps around every HTML element. It consists of:
borders, padding, margins, and the actual content.</p>
<div>This text is the content of the box. We have added a 50px padding, 20px margin and a 15px
green border. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.</div>
</body>
</html>
Output
Penjelasan
Pada CSS Box Model, konsep dimana setiap element yang terdapat pada halaman web
diproses sebagai kotak (box). Masing-masing HTML ini terdiri dari 4 lapisan, yaitu konten
(isi), padding, border, dan margin. Keempat lapisan inilah yang membangun CSS Box
Model.
CSS Box Model Width & Height of an Element
Code
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 320px;
padding: 10px;
border: 5px solid gray;
margin: 0;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Fungsi width and heigith pada CSS Box Model adalah untuk mengatur lebar dan tinggi area
konten.
CSS Basic Dropdown
Code
<!DOCTYPE html>
<html>
<head>
<style>
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
</head>
<body>
<h2>Hoverable Dropdown</h2>
<p>Move the mouse over the text below to open the dropdown content.</p>
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
</body>
</html>
Output
Penjelasan
Membuat basic dropdown yang akan muncul apabila suatu kalimat yang sudah ditentukan
ditunjuk oleh kursor.
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
</style>
</head>
<body>
Output
Penjelasan
Membuat menu dropdown yang memiliki beberapa pilihan.
CSS Right-aligned Dropdown content.
<!DOCTYPE html>
<html>
<head>
<style>
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
Code
.dropdown-content a:hover {background-color: #f1f1f1;}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Membuat menu dropdown dengan alinea kanan/kiri.
CSS Dropdown Image
Code
<!DOCTYPE html>
<html>
<head>
<style>
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown:hover .dropdown-content {
display: block;
}
.desc {
padding: 15px;
text-align: center;
}
</style>
</head>
<body>
<h2>Dropdown Image</h2>
<p>Move the mouse over the image below to open the dropdown content.</p>
<div class="dropdown">
<img src="img_5terre.jpg" alt="Cinque Terre" width="100" height="50">
<div class="dropdown-content">
<img src="img_5terre.jpg" alt="Cinque Terre" width="300" height="200">
<div class="desc">Beautiful Cinque Terre</div>
</div>
</div>
</body>
</html>
Output
Penjelasan
Membuat dropdown pada gambar dan memunculkan gambar.
CSS Dropdown Navigation Bar
Code
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
</head>
<body>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn">Dropdown</a>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</li>
</ul>
</body>
</html>
Output
Penjelasan
Membuat dropdown pada navigation bar
CSS Float Right
Code
<!DOCTYPE html>
<html>
<head>
<style>
img {
float: right;
}
</style>
</head>
<body>
<p>In this example, the image will float to the right in the paragraph, and the text in the
paragraph will wrap around the image.</p>
</body>
</html>
Output
Penjelasan
Untuk melayangkan elemen di kanan
CSS Float Left
Code
<!DOCTYPE html>
<html>
<head>
<style>
img {
float: left;
}
</style>
</head>
<body>
<p>In this example, the image will float to the left in the paragraph, and the text in the
paragraph will wrap around the image.</p>
<p><img src="pineapple.jpg" alt="Pineapple" style="width:170px;height:170px;margin-
right:15px;">
Apple pen.</p>
</body>
</html>
Output
Penjelasan
Untuk melayangkan elemen di kiri
CSS No float
Code
<!DOCTYPE html>
<html>
<head>
<style>
img {
float: none;
}
</style>
</head>
<body>
<p>In this example, the image will be displayed just where it occurs in the text (float: none;).</p>
</body>
</html>
Output
Penjelasan
Untuk tidak melayangkan gambar.
CSS The Clear Property
Code
<!DOCTYPE html>
<html>
<head>
<style>
.div1 {
float: left;
width: 100px;
height: 50px;
margin: 10px;
border: 3px solid #73AD21;
}
.div2 {
border: 1px solid red;
}
.div3 {
float: left;
width: 100px;
height: 50px;
margin: 10px;
border: 3px solid #73AD21;
}
.div4 {
border: 1px solid red;
clear: left;
}
</style>
</head>
<body>
<h2>Without clear</h2>
<div class="div1">div1</div>
<div class="div2">div2 - Notice that div2 is after div1 in the HTML code. However, since div1 floats to
the left, the text in div2 flows around div1.</div>
<br><br>
<h2>With clear</h2>
<div class="div3">div3</div>
<div class="div4">div4 - Here, clear: left; moves div4 down below the floating div3. The value "left"
clears elements floated to the left. You can also clear "right" and "both".</div>
</body>
</html>
Output
Penjelasan
Untuk memberikan kejelasan agar 2 div elemen tidak bertabrakan
CSS Float The clearfix hack
Code
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 3px solid #4CAF50;
padding: 5px;
}
.img1 {
float: right;
}
.clearfix {
overflow: auto;
}
.img2 {
float: right;
}
</style>
</head>
<body>
<p>In this example, the image is taller than the element containing it, and it is floated, so it
overflows outside of its container:</p>
<div>
<img class="img1" src="pineapple.jpg" alt="Pineapple" width="170" height="170">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum
interdum...
</div>
<p style="clear:right">Add a clearfix class with overflow: auto; to the containing element, to fix this
problem:</p>
<div class="clearfix">
<img class="img2" src="pineapple.jpg" alt="Pineapple" width="170" height="170">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum
interdum...
</div>
</body>
</html>
Output
Penjelasan
Untuk memperbaiki gambar yang melayangnya tidak beraturan menjadi teratur.
CSS Float with/without clearfix
Code
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 3px solid #4CAF50;
padding: 5px;
}
.img1 {
float: right;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
.img2 {
float: right;
}
</style>
</head>
<body>
<p>In this example, the image is taller than the element containing it, and it is floated, so it
overflows outside of its container:</p>
<div>
<h2>Without Clearfix</h2>
<img class="img1" src="pineapple.jpg" alt="Pineapple" width="170" height="170">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum
interdum...
</div>
<p style="clear:right">Add the clearfix hack to the containing element, to fix this problem:</p>
<div class="clearfix">
<h2>With Clearfix</h2>
<img class="img2" src="pineapple.jpg" alt="Pineapple" width="170" height="170">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum
interdum...
</div>
</body>
</html>
Output
Penjelasan
Menjelaskan perbedaan apabila div elemen yang melayang tidak diperbaiki
CSS Float Grid Boxes
Code
<!DOCTYPE html>
<html>
<head>
<style>
{
box-sizing: border-box;
}
.box {
float: left;
width: 33.33%;
padding: 50px;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
</style>
</head>
<body>
<h2>Grid of Boxes</h2>
<p>Float boxes side by side:</p>
<div class="clearfix">
<div class="box" style="background-color:#bbb">
<p>Some text inside the box.</p>
</div>
<div class="box" style="background-color:#ccc">
<p>Some text inside the box.</p>
</div>
<div class="box" style="background-color:#ddd">
<p>Some text inside the box.</p>
</div>
</div>
<p>Note that we also use the clearfix hack to take care of the layout flow, and that add the box-
sizing property to make sure that the box doesn't break due to extra padding. Try to remove this
code to see the effect.</p>
</body>
</html>
Output
Penjelasan
Untuk membuat kotak dengan grid
CSS Float Image Side by Side
Code
<!DOCTYPE html>
<html>
<head>
<style>
{
box-sizing: border-box;
}
.img-container {
float: left;
width: 33.33%;
padding: 5px;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
</style>
</head>
<body>
<div class="clearfix">
<div class="img-container">
<img src="img_5terre.jpg" alt="Italy" style="width:100%">
</div>
<div class="img-container">
<img src="img_forest.jpg" alt="Forest" style="width:100%">
</div>
<div class="img-container">
<img src="img_mountains.jpg" alt="Mountains" style="width:100%">
</div>
</div>
<p>Note that we also use the clearfix hack to take care of the layout flow, and that we add the box-
sizing property to make sure that the image container doesn't break due to extra padding. Try to
remove this code to see the effect.</p>
</body>
</html>
Output
Penjelasan
Untuk menampilkan gambar yang melayang dan gambarnya terletak disamping gambar lainnya.
CSS Float Equal Height Boxes
Code
<!DOCTYPE html>
<html>
<head>
<style>
{
box-sizing: border-box;
}
.box {
float: left;
width: 50%;
padding: 50px;
height: 300px;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
</style>
</head>
<body>
<h2>Equal Height Boxes</h2>
<p>Floating boxes with equal heights:</p>
<div class="clearfix">
<div class="box" style="background-color:#bbb">
<h2>Box 1</h2>
<p>Some content, some content, some content</p>
</div>
<div class="box" style="background-color:#ccc">
<h2>Box 2</h2>
<p>Some content, some content, some content</p>
<p>Some content, some content, some content</p>
<p>Some content, some content, some content</p>
</div>
</div>
<p>This example not very flexible. It is ok to use CSS height if you can guarantee that the boxes will
always have the same amount of content in them, but that's not always the case. If you try the
example above on a mobile phone (or resize the browser window), you will see that the second
box's content will be displayed outside of the box.</p>
<p>Go back to the tutorial and find another solution, if this is not what you want.</p>
</body>
</html>
Output
Penjelasan
Untuk membuat dua kotak dengan tinggi yang sama dan menempel
CSS Float Flexbox
Code
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
flex-wrap: nowrap;
background-color: DodgerBlue;
}
.flex-container .box {
background-color: #f1f1f1;
width: 50%;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
}
</style>
</head>
<body>
<h1>Flexible Boxes</h1>
<div class="flex-container">
<div class="box">Box 1 - This is some text to make sure that the content gets really tall. This is some
text to make sure that the content gets really tall.</div>
<div class="box">Box 2 - My height will follow Box 1.</div>
</div>
</body>
</html>
Output
Penjelasan
Untuk membuat kotak yang fleksibel
CSS Float Navigation Menu
Code
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
.active {
background-color: red;
}
</style>
</head>
<body>
<ul>
<li><a href="#home" class="active">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
</body>
</html>
Output
Penjelasan
Untuk membuat menu navigasi
CSS Float
Code
<!DOCTYPE html>
<html>
<head>
<style>
{
box-sizing: border-box;
}
.header, .footer {
background-color: grey;
color: white;
padding: 15px;
}
.column {
float: left;
padding: 15px;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
.menu {
width: 25%;
}
.content {
width: 75%;
}
.menu ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.menu li {
padding: 8px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
}
.menu li:hover {
background-color: #0099cc;
}
</style>
</head>
<body>
<div class="header">
<h1>Chania</h1>
</div>
<div class="clearfix">
<div class="column menu">
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div>
<div class="footer">
<p>Footer Text</p>
</div>
</body>
</html>
Output
Penjelasan
Untuk membuat contoh layout tampilan web
<html>
<head>
<style>
Output
Penjelasan
Untuk menuliskan font dapat menggunakan font-family dengan memberi tipe font yang diinginkan.lalu
diberikan keterangan “class” / “sansseriff” untuk ditampilkan dalam bentuk paragraph.
CSS Font Style
Code
<!DOCTYPE html>
<html>
<head>
<style>
p.normal {
font-style: normal;
p.italic {
font-style: italic;
p.oblique {
font-style: oblique;
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Untuk bentuk tipe penulisan dapat menggunakan font-style dengan memberi tipe font yang diinginkan tidak
lupa diberi class . Sehingga pada penulisan di tags paragraf kita dapat menuliskan tipe font yang ditulis
sebelumnya,
CSS Set Font Size with Pixels
Code
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
font-size: 40px;
h2 {
font-size: 30px;
p{
font-size: 14px;
</style>
</head>
<body>
<p>This is a paragraph.</p>
</body>
</html>
Penjelasan
Dalam css kita dapat menggunakan pixels untuk ukuran, dengan menggunakan font size lalu diberi dengan
ukuran pixel yang ingin ditampilkan penulisan dengan menuliskan huruf p untuk paragraph atau h untuk
heading kemudian diberi {} untuk menampilkan tulisan . Urutan penulisan perlu diperhatikan jika
menggunakan lebih dari 1.
<html>
<head>
<style>
Output
Penjelasan
Selain menggunakan pixel kita dapat menggunakan em. Em adalah bentuk pixel yang di re-size sehingga lebih
kecil untuk penulisan karena em = pixels/16. Penulisan syntax sama seperti sebelumnya yaitu menggunakan
p/h lalu diberi {} dan font size.
<!DOCTYPE html>
<html>
<head>
<style>
Output
Penjelasan
Kita juga dapat menggunakan persentase untuk format penulisan yang digunakan dapat menggunakan h
untuk heading , p untuk tulisan paragraph dan h untuk heading lalu {} dengan font-size dan ukuran persentase
nya.
<!DOCTYPE html>
<html>
<head>
<style>
Output
Penjelasan
Kita dapat menggunakan weight dimana tampilan seperti tebal atau tipisnya suatu tulisan. Untuk penulisan
syntax karena paragraph maka p lalu diberi keterangan seperti thick,light dsb kemudian pada isi {} diberi font-
weight dengan keterangan sesuai pada keterangan setelah p.
CSS Responsive Font Sizes
Code
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output
Penjelasan
Penggunaan vw atau viewport width adalah untuk menampilkan text sesuai ukuran tampilan pada windows
namun tampilan tidak berubah saat skala kita rubah berbeda dengan tulisan yang lain karena penulisan sudah
disesuaikan semisal 10% dari tampilan windows. Untuk syntax menggunakann font-size seperti sebelum-
sebelumnya.
CSS Font Variant
Code
<!DOCTYPE html>
<html>
<head>
<style>
p.normal {
font-variant: normal;
p.small {
font-variant: small-caps;
</style>
</head>
<body>
Output </body>
</html>
Penjelasan
Untuk font variant tujuannya adalah menampilkan tulisan dengan tipe font yang diinginkan . Dalam hal ini ,
apabila kita memberi tipe font – caps maka tulisan yang awalnya huruf kecil menjadi huruf balok/besar. Untuk
syntax penulisan mengguanakn font-variant : lalu diberi keterangan font yang diinginkan seperti penulisan
font weight.
CSS Awesome Icons
Code
<!DOCTYPE html>
<html>
<head>
<title>Font Awesome Icons</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
<!--Get your own code at fontawesome.com-->
</head>
<body>
</body>
</html>
Output
Penjelasan
Untuk menampilkan ikon
CSS Bootstrap Icon
Code
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Icons</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body class="container">
</body>
</html>
Penjelasan
Untuk menampilkan ikon dari Bootstrap
</body>
</html>
Output
Penjelasan
Untuk menampilkan ikon dari google.
CSS Syling Links
Code
<!DOCTYPE html>
<html>
<head>
<style>
/* unvisited link */
a:link {
color: red;
}
/* visited link */
a:visited {
color: green;
}
/* selected link */
a:active {
color: blue;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
link untuk unvisited, :visited efek untuk setelah diklik, :hover ketika mouse di atas link,
:active ketika mouse mengklik.
CSS Links
<!DOCTYPE html>
<html>
<head>
<style>
a {
color: hotpink;
}
</style>
</head>
<body>
</body>
</html>
Code
Output
Penjelasan
gunakan tag a pada style untuk menambah efek pada link
<!DOCTYPE html>
<html>
<head>
<style>
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: underline;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
urutannya adalah :link, :visited, :hover, :active
CSS Bacgorund Color
Code
<!DOCTYPE html>
<html>
<head>
<style>
a:link {
background-color: yellow;
}
a:visited {
background-color: cyan;
}
a:hover {
background-color: lightgreen;
}
a:active {
background-color: hotpink;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
mengatur warna background link dengan atribut background-color pada tag a.
CSS Advance Link Buttons
Code
<!DOCTYPE html>
<html>
<head>
<style>
a:link, a:visited {
background-color: #f44336;
color: white;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
}
a:hover, a:active {
background-color: red;
}
</style>
</head>
<body>
<h2>Link Button</h2>
<p>A link styled as a button:</p>
<a href="default.asp" target="_blank">This is a link</a>
</body>
</html>
Output
Penjelasan
kita bisa menampilkan link seperti tombol dengan css
Override The Default Display Value
Listing Program
<!DOCTYPE html>
<html>
<head>
<style>
li {
display: inline;
}
</style>
</head>
<body>
<ul>
<li><a href="/html/default.asp" target="_blank">HTML</a></li>
<li><a href="/css/default.asp" target="_blank">CSS</a></li>
<li><a href="/js/default.asp" target="_blank">JavaScript</a></li>
</ul>
</body>
</html>
Output
Penjelasan
Untuk menampilkan navigasi menu secara horizontal
Block
Listing Program
<!DOCTYPE html>
<html>
<head>
<style>
span {
display: block;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
<span> digunakan untuk memindahkan kalimat menjadi dibawahnya.
Display : none
Listing Program
<!DOCTYPE html>
<html>
<head>
<style>
h1.hidden {
display: none;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Display : none digunakan style untuk tidak menampilkan apapun
Hidden
Listing Program
<!DOCTYPE html>
<html>
<head>
<style>
h1.sembunyi {
visibility: hidden;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasna
Hidden digunakan ketika ingin menyembunyikan sesuatu dan Nampak masih di tempat.
CSS Layout – Inline Block
Listing Program
Output
Penjelasan
nilai inline-blok properti tampilan membuatnya lebih mudah dibaca.
Using inline-block to Create Navigation Links
Listing Program
Output
Penjelasan
nilai inline-blok properti tampilan membuatnya lebih mudah dibaca.
Penjelasan
Untuk membuat sebuah album foto
Different List Item Maker
Listing Program
<!DOCTYPE html>
<html>
<head>
<style>
ul.a {
list-style-type: circle;
}
ul.b {
list-style-type: square;
}
ol.c {
list-style-type: upper-roman;
}
ol.d {
list-style-type: lower-alpha;
}
</style>
</head>
<body>
<ul class="b">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ol class="d">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
</body>
</html>
Analisa: Program diatas merupakan
program yang mendesain untuk
membuat beberapa type list.
Contohnya seperti yang ada di samping
ini. List nya ada bulat, kotak, huruf
romawi, dan juga abc.
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-image: url('sqpurple.gif');
}
</style>
</head>
<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>
</html>
Analisa: Program di atas merupakan program
yang mendesain untuk list itemnya. Program
diatas menggunakan image untuk list itemnya.
ul.b {
list-style-position: inside;
}
</style>
</head>
<body>
<h2>list-style-position: inside:</h2>
<ul class="b">
<li>Coffee - A brewed drink prepared from roasted coffee beans, which are the
seeds of berries from the Coffea plant</li>
<li>Tea - An aromatic beverage commonly prepared by pouring hot or boiling water
over cured leaves of the Camellia sinensis, an evergreen shrub (bush) native to
Asia</li>
<li>Coca Cola - A carbonated soft drink produced by The Coca-Cola Company. The
drink's name refers to two of its original ingredients, which were kola nuts (a
source of caffeine) and coca leaves</li>
</ul>
</body>
Output
Analisa: program di atas merupakan program yang mendesain list. Program tersebut
membedakan anatar posisi list, yang satu outside dan yang satu inside. Yang inside listnya
agak menjorok ke dalam.
<p>Default list:</p>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>
</html>
Analisa: program di atas merupakan program
untuk mendesain list. Program tersebut
menampilkan cara menghapus list. Output dari
program tersebut yang pertama ada list item
nya dan yang kedua tidak ada.
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>
</html>
ul {
background: #3399ff;
padding: 20px;
}
ol li {
background: #ffe5e5;
padding: 5px;
margin-left: 35px;
}
ul li {
background: #cce5ff;
margin: 5px;
}
</style>
</head>
<body>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>
</html>
Output
Analisa: Program di atas merupakan program mendesain list itemnya. Program tersebut
menampilkan dua type list item yang berbeda, yang pertama ada 123 dan yang kedua ada titik.
Keuda output terdapat background warna berbeda.
<!DOCTYPE html>
<html>
<head>
<style>
div.ex1 {
width:500px;
margin: auto;
border: 3px solid #73AD21;
}
div.ex2 {
max-width:500px;
margin: auto;
border: 3px solid #73AD21;
}
</style>
</head>
<body>
<div class="ex1">This div element has width: 500px;</div>
<br>
<p><strong>Tip:</strong> Drag the browser window to smaller than 500px wide, to see the
difference between
the two divs!</p>
</body>
</html>
Output
<h1>Image Transparency</h1>
<p>The opacity property specifies the transparency of an
element. The lower the value, the more transparent:</p>
</body>
</html>
Output
img:hover {
opacity: 1.0;
filter: alpha(opacity=100); /* For IE8 and earlier */
}
</style>
</head>
<body>
<h1>Image Transparency</h1>
<p>The opacity property is often used together with the :hover selector to
change the opacity on mouse-over:</p>
<img src="tgs1.jpg" alt="Forest" width="170" height="100">
<img src="tgs2.jpg" alt="Mountains" width="170" height="100">
</body>
</html>
Output
Penjelasan : Hover digunakan untuk mengubah opacity menjadi lebih terang menggunakan
pointer mouse
Esample Explained’
Code
<!DOCTYPE html>
<html>
<head>
<style>
img:hover {
opacity: 0.5;
filter: alpha(opacity=50); /* For IE8 and earlier */
}
</style>
</head>
<body>
<h1>Image Transparency</h1>
<p>The opacity property is often used together with the :hover selector to change
the opacity on mouse-over:</p>
<img src="tgs1.jpg" alt="Forest" width="170" height="100">
<img src="tgs2.jpg" alt="Mountains" width="170" height="100">
<p><b>Note:</b> In IE, a !DOCTYPE must be added for the :hover selector to work on
other elements than the a element.</p>
</body>
</html>
Output
Penjelasan : Fungsi reserved hover merupakan kebalikan dari hover, mengubah gambar
berwarna terang menjadi tasparant menggunakan pointer
Transparent Box
Code
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color: #FF007F;
padding: 10px;
}
div.first {
opacity: 0.1;
filter: alpha(opacity=10); /* For IE8 and earlier */
}
div.second {
opacity: 0.3;
filter: alpha(opacity=30); /* For IE8 and earlier */
}
div.third {
opacity: 0.6;
filter: alpha(opacity=60); /* For IE8 and earlier */
}
</style>
</head>
<body>
<h1>Transparent Box</h1>
<p>When using the opacity property to add transparency to the background of
an element, all of its child elements become transparent as well. This can
make the text inside a fully transparent element hard to read:</p>
Output
<!DOCTYPE html>
<html>
<head>
<style>
div {
background: rgb(76, 175, 80);
padding: 10px;
}
div.first {
background: rgba(76, 175, 80, 0.1);
}
div.second {
background: rgba(76, 175, 80, 0.3);
}
div.third {
background: rgba(76, 175, 80, 0.6);
}
</style>
</head>
<body>
<h1>Transparent Box</h1>
<p>With opacity:</p>
<div style="opacity:0.1;"><p>10% opacity</p></div>
<div style="opacity:0.3;"><p>30% opacity</p></div>
<div style="opacity:0.6;"><p>60% opacity</p></div>
<div><p>opacity 1</p></div>
<p>Notice how the text gets transparent as well as the background color when using
the opacity property.</p>
</body>
</html>
Output
Penjelasan : Menerapkan opacity pada box yang menggunakan RGBA
Text in Transparent Box
Code
<!DOCTYPE html>
<html>
<head>
<style>
div.background {
background: url(tgs1.jpg) repeat;
border: 2px solid black;
}
div.transbox {
margin: 30px;
background-color: #ffffff;
border: 1px solid black;
opacity: 0.6;
filter: alpha(opacity=60); /* For IE8 and earlier */
}
div.transbox p {
margin: 5%;
font-weight: bold;
color: #000000;
}
</style>
</head>
<body>
<div class="background">
<div class="transbox">
<p>Dan Jakarta Muram Kehilanganmu</p>
</div>
</div>
Output
</body>
</html>
Penjelasan : Menulis pada background yang bergambar dan memiliki bodir, serta pada
bagian box diberi opacity
Example
<!DOCTYPE html>
<html>
<head>
<style>
div {
padding: 70px;
border: 1px solid #4CAF50;
}
</style>
</head>
<body>
</body>
</html>
Individual sides
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 1px solid black;
background-color: lightblue;
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
}
</style>
</head>
<body>
</body>
</html>
</body>
</html>
</body>
</html>
</body>
</html>
div.ex2 {
width: 300px;
padding: 25px;
background-color: lightblue;
}
</style>
</head>
<body>
</body>
</html>
Padding and element width with box-sizing
<!DOCTYPE html>
<html>
<head>
<style>
div.ex1 {
width: 300px;
background-color: yellow;
}
div.ex2 {
width: 300px;
padding: 25px;
box-sizing: border-box;
background-color: lightblue;
}
</style>
</head>
<body>
</body>
</html>
Override The Default Display Value
Listing Program
<!DOCTYPE html>
<html>
<head>
<style>
li {
display: inline;
}
</style>
</head>
<body>
<ul>
<li><a href="/html/default.asp" target="_blank">HTML</a></li>
<li><a href="/css/default.asp" target="_blank">CSS</a></li>
<li><a href="/js/default.asp" target="_blank">JavaScript</a></li>
</ul>
</body>
</html>
Output
Penjelasan
Untuk menampilkan navigasi menu secara horizontal
Block
Listing Program
<!DOCTYPE html>
<html>
<head>
<style>
span {
display: block;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
<span> digunakan untuk memindahkan kalimat menjadi dibawahnya.
Display : none
Listing Program
<!DOCTYPE html>
<html>
<head>
<style>
h1.hidden {
display: none;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Display : none digunakan style untuk tidak menampilkan apapun
Hidden
Listing Program
<!DOCTYPE html>
<html>
<head>
<style>
h1.sembunyi {
visibility: hidden;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasna
Hidden digunakan ketika ingin menyembunyikan sesuatu dan Nampak masih di tempat.
Anchor Pseudo-Classes
head>
<style>
/* link yang tidak dikunjungi */
a:link {
color: red;
}
</body>
div:hover {
background-color: blue;
}
</style>
</head>
<body>
</body>
Penjelasan : untuk mengganti warna suatu background bila ditunjukk dengan pointer
Simple Tooltip Hover
<head>
<style>
p:first-child {
color: blue;
}
</style>
</head>
<body>
</body>
</body>
Penjelasan : untuk membuat kata dtrong pertama pada setiap paragraph menjadi berwarna
biru
Match the first <i> element in all <p> elements
<head>
<style>
p:first-child i {
color: blue;
}
</style>
</head>
<body>
Penjelasan : untuk membuat kata strong di pargaraf awal menjadi berwarna biru
Match all <i> elements in all first child <p> elements
<head>
<style>
q:lang(no) {
quotes: "~" "~";
}
</style>
</head>
<body>
</body>
Penjelasan : untuk memberi suat quotation dalam text dengan menginisialisasi quote itu
<html>
<head>
<style>
p::first-line {
color: #ff0000;
font-variant: small-caps;
</style>
</head>
<body>
<p>You can use the ::first-line pseudo-element to add a special effect to the first line of a text. Some
more text. And even more, and more, and more, and more, and more, and more, and more, and
more, and more, and more, and more, and more.</p>
</body>
</html>
Output:
Input :
<!DOCTYPE html>
<html>
<head>
<style>
p::first-letter {
color: #ff0000;
font-size: xx-large;
</style>
</head>
<body>
<p>You can use the ::first-letter pseudo-element to add a special effect to the first character of a
text!</p>
</body>
</html>
Output
Input :
<!DOCTYPE html>
<html>
<head>
<style>
p.intro::first-letter {
color: #ff0000;
font-size:200%;
</style>
</head>
<body>
<p class="intro">This is an introduction.</p>
</body>
</html>
Output:
Input:
<!DOCTYPE html>
<html>
<head>
<style>
p::first-letter {
color: #ff0000;
font-size: xx-large;
p::first-line {
color: #0000ff;
font-variant: small-caps;
</style>
</head>
<body>
<p>You can combine the ::first-letter and ::first-line pseudo-elements to add a special effect to the
first letter and the first line of a text!</p>
</body>
</html>
Output:
Input:
<!DOCTYPE html>
<html>
<head>
<style>
h1::before {
content: url(smiley.gif);
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<h1>This is a heading</h1>
</body>
</html>
Output:
Analisa: penggunaan ::before digunakan untuk membuat apa yang akan kita insert sebelum pseudo
element
<!DOCTYPE html>
<html>
<head>
<style>
h1::after {
content: url(smiley.gif);
</style>
</head>
<body>
<h1>This is a heading</h1>
<h1>This is a heading</h1>
</body>
</html>
Output:
Analisa: penggunaan ::after digunakan untuk membuat apa yang akan kita insert setelah pseudo
element
Input:
<!DOCTYPE html>
<html>
<head>
<style>
color: red;
background: yellow;
::selection {
color: red;
background: yellow;
</style>
</head>
<body>
<p>This is a paragraph.</p>
</body>
</html>
Output:
Analisa:
Penggunaan ::selection digunakan jika kita selection/block maka warna akan berubah
CSS Tables
Source Code
<!DOCTYPE html>
<html>
<head>
<style>
#customers {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#customers th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<table id="customers">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Berglunds snabbköp</td>
<td>Christina Berglund</td>
<td>Sweden</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Königlich Essen</td>
<td>Philip Cramer</td>
<td>Germany</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>North/South</td>
<td>Simon Crowther</td>
<td>UK</td>
</tr>
<tr>
<td>Paris spécialités</td>
<td>Marie Bertrand</td>
<td>France</td>
</tr>
</table>
</body>
</html>
Output
Analisa
Kita juga dapat membuat table dalam css. Tag yang digunakan untuk membuat table pada css
sama dengan HTML seperti tag TH, TD, TR dan lainnya.
Tables Border
Source Code
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
</table>
</body>
</html>
Output
Analisa
Kita dapat mengatur border dari suatu table dengan menggunakan property border dan
memasukkan valuenya.
Collapse Table Borders
Source Code
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
</table>
</body>
</html>
Output
Output
Analisa
Dalam CSS, warna dari table dapat diatur. Namun, tidak semua browser mensupport html5 sehingga
hasil dari table yang diformat dengan CSS dapat berbeda.
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
Output<td>Lois</td>
<td>Griffin</td>
</tr>
</table>
</body>
</html>
Output
Analisa
Dalam CSS, table yang dibuat dapat memiliki 1 border saya. Untuk membuatnya dapat diigunakan
border collapse.
Table Width and Weight
Source Code
<!DOCTYPE html>
<html>
<head>
<style>
table, td, th {
border: 1px solid black;
}
table {
border-collapse: collapse;
width: 100%;
}
th {
height: 50px;
}
</style>
</head>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Savings</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
<td>$100</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
<td>$150</td>
</tr>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300</td>
</tr>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250</td>
</tr>
</table>
</body>
</html>
Output
Analisa
Dalam CSS, table yang dibuat dapat diatur tinggi dan lebarnya. Untuk membuatnya dapat
diigunakan property width dan weight.
Horizontal Alighment
Source Code
<!DOCTYPE html>
<html>
<head>
<style>
table, td, th {
border: 1px solid black;
}
table {
border-collapse: collapse;
width: 100%;
}
th {
text-align: left;
}
</style>
</head>
<body>
<h2>The text-align Property</h2>
<p>This property sets the horizontal alignment (like left, right, or center) of the content in
th or td:</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Savings</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
<td>$100</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
<td>$150</td>
</tr>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250</td>
</tr>
</table>
</body>
</html>
Output
Analisa
Kita dapat mengatur pertaaan dari text yang ada didalam table dengan menggunakan
property text alignment.
Vertical Alighment
Source Code
<!DOCTYPE html>
<html>
<head>
<style>
table, td, th {
border: 1px solid black;
}
table {
border-collapse: collapse;
width: 100%;
}
td {
height: 50px;
vertical-align: bottom;
}
</style>
</head>
<body>
<tr>
<td>Peter</td>
<td>Griffin</td>
<td>$100</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
<td>$150</td>
</tr>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250</td>
</tr>
</table>
</body>
</html>
Output
Analisa
Kita dapat mengatur pertaaan dari text yang ada didalam table secara dengan
menggunakan property vertical alignment.
Table Padding
Source Code
<!DOCTYPE html>
<html>
<head>
<style>
table, td, th {
border: 1px solid #ddd;
text-align: left;
}
table {
border-collapse: collapse;
width: 100%;
}
th, td {
padding: 15px;
}
</style>
</head>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Savings</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
<td>$100</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
<td>$150</td>
</tr>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250</td>
</tr>
</table>
</body>
</html>
Output
Analisa
Cell padding digunakan untuk mengatur jarak antara text dengan sisi horizontal dan vertical
table.
Horizontal Deviders
Source Code
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
</style>
</head>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Savings</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
<td>$100</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
<td>$150</td>
</tr>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
Output
Analisa
Horizontal table deviders adalah sebuah table yang tidak memiliki border disisi kanan dan
kirinya. Tabel ini hanya memiliki border dibagian bawahnya.
Hoverable Table
Source Code
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
tr:hover {background-color:#f5f5f5;}
</style>
</head>
<body>
<h2>Hoverable Table</h2>
<p>Move the mouse over the table rows to see the effect.</p>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Points</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
<td>$100</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
<td>$150</td>
</tr>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250</td>
Output
Analisa
Hoverable Table akan membuat table memiliki effect ketika mouse melewati table tersebut.
Stripped Tables
Sorce Code
<!DOCTYPE html>
<html>
<head>
<style>
table {
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250</td>
</tr>
</table>
Output
Analisa
Stripped table digunakan untuk membuat table dengan warna yang berselang seling. Style
table seperti ini akan memudahkan pembaca dalam membaca isi table.
Table Color
Sorce Code
<!DOCTYPE html>
<html>
<head>
<style>
table {
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250</td>
</tr>
</table>
</body>
Output
Analisa
Warna pada table CSS dapat diganti. Untuk member warna pada table digunakan property
tr.
Responsive Table
Sorce Code
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
<td>50</td>
</tr>
Output
Analisa
Responsive table adalah table yang dapat diseger view nya apabila jendela dari browser
tidak cukup. Untuk membuat responsive table dapat menggunakan property overflow dan
value auto.
Text color
Script
<style>
body {
color: red;
}
h1 {
color: black;
}
</style>
</head>
<body>
<h1>ini heading</h1>
<p>This is an ordinary paragraph. Notice
that this text is blue. The default text
color for a page is defined in the body
selector.</p>
Output
Analisa : Dalam css ini kita tidak menggunakan file tersendiri yang dihubungkan melalui link,
namun kita menggunakan elemen style, dalam file css ini terdapat body dan h1 yang diberi
style, yaitu dengan style color yang akan merubah warna dari teks yang terdapat di
dalamnya. Untuk nilai dari color sendiri dapat berupa nama dari sebuah warna, kode hex,
ataupun rgb.
Text align
Script
<style>
h1 {
text-align: center;
}
h2 {
text-align: left;
}
h3 {
text-align: right;
}
</style>
</head>
<body>
<h1>Heading 1 (center)</h1>
<h2>Heading 2 (left)</h2>
<h3>Heading 3 (right)</h3>
Analisa : Kemudian di sini terdapat text-align yang berfungsi untuk merubah poisisi dari
suatu teks, nilai dari text-align sendiri adalah left, right, dan center, dan semuanya mewakili
di mana nantinya teks akan berada.
Text align
Script
<style>
h1 {
text-align: center;
}
h2 {
text-align: left;
}
h3 {
text-align: right;
}
</style>
</head>
<body>
<h1>Heading 1 (center)</h1>
<h2>Heading 2 (left)</h2>
<h3>Heading 3 (right)</h3>
Analisa : Kemudian di sini terdapat text-align yang berfungsi untuk merubah poisisi dari
suatu teks, nilai dari text-align sendiri adalah left, right, dan center, dan semuanya mewakili
di mana nantinya teks akan berada.
Script
<style>
div {
border: 1px solid black;
padding: 10px;
width: 200px;
height: 200px;
text-align: justify;
}
</style>
</head>
<body>
<div>
In my younger and more vulnerable years my father gave me some
advice that I've been turning over in my mind ever since.
'Whenever you feel like criticizing anyone,' he told me, 'just
remember that all the people in this world haven't had the
advantages that you've had.'
</div>
Output
Analisa : Kita juga dapat memberi nilai justify pada text-align sehingga setiap baris
mempunyai lebar yang sama.
Text decoration
Script
<style>
a {
text-decoration: none;
}
</style>
</head>
<body>
Output
h2 {
text-decoration: line-through;
}
h3 {
text-decoration: underline;
}
</style>
</head>
<body>
p.lowercase {
text-transform: lowercase;
}
p.capitalize {
text-transform: capitalize;
}
</style>
</head>
<body>
Analisa : elemen ini berguna untuk menentukan seberapa menjoroknya awal suatu kalimat
ke arah dalam. Semakin besar dari elemen text-indet, maka akan semakin menjorok ke
dalam.
Letter spacing
Script
<style>
h1 {
letter-spacing: 3px;
}
h2 {
letter-spacing: -3px;
}
</style>
</head>
<body>
Output
Analisa : elemen letter-spacing bertujuan untuk menentukan jarak antar karakter di suatu
teks.
Line height
Script
<style>
p.small {
line-height: 0.7;
}
p.big {
line-height: 1.8;
}
</style>
</head>
<body>
<p>
This is a paragraph with a standard
line-height.<br>
The default line height in most browsers
is about 110% to 120%.<br>
</p>
<p class="small">
This is a paragraph with a smaller line-
height.<br>
This is a paragraph with a smaller line-
height.<br>
</p>
<p class="big">
This is a paragraph with a bigger line-
height.<br>
This is a paragraph with a bigger line-
height.<br>
</p>
Output
Analisa : elemen line-height berfungsi untuk menentukan jarak antar baris, ukuran line-
height standar adalah 110% hingga 120%.
Text direction
Script
p.ex1 {
direction: rtl;
}
</style>
</head>
<body>
Output
Analisa : elemen direction dapat digunakan untuk menentukan arah dari suatu teks yang
kita buat, dalam tag <style> sendiri, kita menggunakan direction dengan nilai rtl yang berarti
right to left, dan otomatis teks akan berpindah ke kanan dan menuju ke kiri, sedangkan
pada html, terdapat tag <bdo> dengan atribut dir yang menunjukkan urutan penulisan yang
dimulai dari kanan ke kiri.
Word spacing
Script
<style>
h1 {
word-spacing: 10px;
}
h2 {
word-spacing: -5px;
}
</style>
</head>
<body>
Output
Text shadow
Script
<style>
h1 {
text-shadow: 3px 2px red;
}
</style>
</head>
<body>
<h1>Text-shadow effect</h1>
<p><b>Note:</b> Internet Explorer 9 and
earlier do not support the text-shadow
property.</p>
Output
Analisa : elemen ini berguna untuk memberikan shadow atau bayangan pada teks, dengan
nilai yang merepresentasikan (x y warna), jadi shadow di sumbu x dan y berapa ukurannya
beserta warnanya.
Image Sprites Simple Example
Code
<!DOCTYPE html>
<html>
<head>
<style>
#home {
width: 46px;
height: 44px;
background: url(img_navsprites.gif) 0 0;
}
#next {
width: 43px;
height: 44px;
background: url(img_navsprites.gif) -91px 0;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Untuk menampilkan gambar yang simple
Image Sprites – Create Navigation List
Code
<!DOCTYPE html>
<html>
<head>
<style>
#navlist {
position: relative;
}
#navlist li {
margin: 0;
padding: 0;
list-style: none;
position: absolute;
top: 0;
}
#home {
left: 0px;
width: 46px;
background: url('img_navsprites.gif') 0 0;
}
#prev {
left: 63px;
width: 43px;
background: url('img_navsprites.gif') -47px 0;
}
#next {
left: 129px;
width: 43px;
background: url('img_navsprites.gif') -91px 0;
}
</style>
</head>
<body>
<ul id="navlist">
<li id="home"><a href="default.asp"></a></li>
<li id="prev"><a href="css_intro.asp"></a></li>
<li id="next"><a href="css_syntax.asp"></a></li>
</ul>
</body>
</html>
Output
Penjelasan
Untuk menggunakan gambar sebagai navigasi link
Image Spirtes Hover
Code
<!DOCTYPE html>
<html>
<head>
<style>
#navlist {
position: relative;
}
#navlist li {
margin: 0;
padding: 0;
list-style: none;
position: absolute;
top: 0;
}
#home {
left: 0px;
width: 46px;
background: url('img_navsprites_hover.gif') 0 0;
}
#prev {
left: 63px;
width: 43px;
background: url('img_navsprites_hover.gif') -47px 0;
}
#next {
left: 129px;
width: 43px;
background: url('img_navsprites_hover.gif') -91px 0;
}
#home a:hover {
background: url('img_navsprites_hover.gif') 0 -45px;
}
#prev a:hover {
background: url('img_navsprites_hover.gif') -47px -45px;
}
#next a:hover {
background: url('img_navsprites_hover.gif') -91px -45px;
}
</style>
</head>
<body>
<ul id="navlist">
<li id="home"><a href="default.asp"></a></li>
<li id="prev"><a href="css_intro.asp"></a></li>
<li id="next"><a href="css_syntax.asp"></a></li>
</ul>
</body>
</html>
Output
Penjelasan
Untuk menggunakan gambar sebagai navigasi link dengan efek hover
Attr selector
Code
<!DOCTYPE html>
<html>
<head>
<style>
a[target] {
background-color: yellow;
}
</style>
</head>
<body>
<a href="https://www.w3schools.com">w3schools.com</a>
<a href="http://www.disney.com" target="_blank">disney.com</a>
<a href="http://www.wikipedia.org" target="_top">wikipedia.org</a>
</body>
</html>
Output
Penjelasna
Untuk memberikan tanda dengan menargetkan atribut lewat selector
<a href="https://www.w3schools.com">w3schools.com</a>
<a href="http://www.disney.com" target="_blank">disney.com</a>
<a href="http://www.wikipedia.org" target="_top">wikipedia.org</a>
</body>
</html>
Output
Penjelasan
Menggunakan attr selector dengan memberi nilai blank
Attr selector value specific
Code
<!DOCTYPE html>
<html>
<head>
<style>
[title~=flower] {
border: 5px solid yellow;
}
</style>
</head>
<body>
<p>All images with the title attribute containing the word "flower" get a yellow border.</p>
</body>
</html>
Output
Penjelasan
Untuk memberi value pada selector spesifik
Attr selector attr|=value
Code
<!DOCTYPE html>
<html>
<head>
<style>
[class|=top] {
background: yellow;
}
</style>
</head>
<body>
<h1 class="top-header">Welcome</h1>
<p class="top-text">Hello world!</p>
<p class="topcontent">Are you learning CSS?</p>
</body>
</html>
Output
Penjelasan
Menggunakan attr|= selector
Attr^= value selector
Code
<!DOCTYPE html>
<html>
<head>
<style>
[class^="top"] {
background: yellow;
}
</style>
</head>
<body>
<h1 class="top-header">Welcome</h1>
<p class="top-text">Hello world!</p>
<p class="topcontent">Are you learning CSS?</p>
</body>
</html>
Output
Penjelasan
Menggunakan attr^=value
Attr$=value selector
Code
<!DOCTYPE html>
<html>
<head>
<style>
[class$="test"] {
background: yellow;
}
</style>
</head>
<body>
<div class="first_test">The first div element.</div>
<div class="second">The second div element.</div>
<div class="my-test">The third div element.</div>
<p class="mytest">This is some text in a paragraph.</p>
</body>
</html>
Output
Penjelasan
Menggunakan attr$=value
Attr*=value selector
Code
<!DOCTYPE html>
<html>
<head>
<style>
[class*="te"] {
background: yellow;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Menggunakan attr*=value selector
Styling Forms
Code
<!DOCTYPE html>
<html>
<head>
<style>
input[type="text"] {
width: 150px;
display: block;
margin-bottom: 10px;
background-color: yellow;
}
input[type="button"] {
width: 120px;
margin-left: 35px;
display: block;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Contoh penerapan
Forms
Code
<!DOCTYPE html>
<html>
<style>
input[type=text], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
div {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
</style>
<body>
<div>
<form action="/action_page.php">
<label for="fname">First Name</label>
<input type="text" id="fname" name="firstname" placeholder="Your name..">
<label for="country">Country</label>
<select id="country" name="country">
<option value="australia">Australia</option>
<option value="canada">Canada</option>
<option value="usa">USA</option>
</select>
</body>
</html>
Output
Penjelasan
Membuat form isian
Styling input
Code
<!DOCTYPE html>
<html>
<head>
<style>
input {
width: 100%;
}
</style>
</head>
<body>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname">
</form>
</body>
</html>
Output
Penjelasan
Membuat dengan width property
Forms Padded inputs
Code
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
</style>
</head>
<body>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lname">
</form>
</body>
</html>
Output
Penjelasan
Ruang teks yang diberi padding
Forms border input
Code
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: 2px solid red;
border-radius: 4px;
}
</style>
</head>
<body>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lname">
</form>
</body>
</html>
Output
Penjelasan
Memberi border pada textfield
Colored input
Code
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: none;
background-color: #3CBC8D;
color: white;
}
</style>
</head>
<body>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname" value="John">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lname" value="Doe">
</form>
</body>
</html>
Output
Penjelasan
Menambah warna pada text field
Focused input 1
Code
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: 1px solid #555;
outline: none;
}
input[type=text]:focus {
background-color: lightblue;
}
</style>
</head>
<body>
<p>In this example, we use the :focus selector to add a background color to the text field
when it gets focused (clicked on):</p>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname" value="John">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lname" value="Doe">
</form>
</body>
</html>
Output
Penjelasan
Akan muncul warna ketika text fields nya ditekan
Focused input 2
Code
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: 3px solid #ccc;
-webkit-transition: 0.5s;
transition: 0.5s;
outline: none;
}
input[type=text]:focus {
border: 3px solid #555;
}
</style>
</head>
<body>
<p>In this example, we use the :focus selector to add a black border color to the text field
when it gets focused (clicked on):</p>
<p>Note that we have added the CSS transition property to animate the border color (takes
0.5 seconds to change the color on focus).</p>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname" value="John">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lname" value="Doe">
</form>
</body>
</html>
Output
Penjelasan
Text fields akan memiliki respon menebalkan border ketika textfields ditekan
Input icon/image
Code
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 100%;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
}
</style>
</head>
<body>
<form>
<input type="text" name="search" placeholder="Search..">
</form>
</body>
</html>
Output
Penjelasan
Memberi icon dan gambar pada text field
Animated icon
Code
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 100%;
}
</style>
</head>
<body>
<form>
<input type="text" name="search" placeholder="Search..">
</form>
</body>
</html>
Output
Penjelasan
Ketika text fields ditekan akan bergerak
Styling text areas
Code
<!DOCTYPE html>
<html>
<head>
<style>
textarea {
width: 100%;
height: 150px;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
background-color: #f8f8f8;
font-size: 16px;
resize: none;
}
</style>
</head>
<body>
<p><strong>Tip:</strong> Use the resize property to prevent textareas from being resized
(disable the "grabber" in the bottom right corner):</p>
<form>
<textarea>Some text...</textarea>
</form>
</body>
</html>
Output
Penjelasan
Untuk memodifikasi textfields agar ukurannya tidak dapat diubah
Styling Select Menus
Code
<!DOCTYPE html>
<html>
<head>
<style>
select {
width: 100%;
padding: 16px 20px;
border: none;
border-radius: 4px;
background-color: #f1f1f1;
}
</style>
</head>
<body>
<form>
<select id="country" name="country">
<option value="au">Australia</option>
<option value="ca">Canada</option>
<option value="usa">USA</option>
</select>
</form>
</body>
</html>
Output
Penjelasan
Untuk memodifikasi menu pilihan
Styling Input buttons
Code
<!DOCTYPE html>
<html>
<head>
<style>
input[type=button], input[type=submit], input[type=reset] {
background-color: #4CAF50;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Memodifikasi tombol
Styling Forms
Code
<!DOCTYPE html>
<html>
<head>
<style>
{
box-sizing: border-box;
}
label {
padding: 12px 12px 12px 0;
display: inline-block;
}
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
float: right;
}
input[type=submit]:hover {
background-color: #45a049;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
.col-25 {
float: left;
width: 25%;
margin-top: 6px;
}
.col-75 {
float: left;
width: 75%;
margin-top: 6px;
}
/* Responsive layout - when the screen is less than 600px wide, make the two columns
stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
.col-25, .col-75, input[type=submit] {
width: 100%;
margin-top: 0;
}
}
</style>
</head>
<body>
<h2>Responsive Form</h2>
<p>Resize the browser window to see the effect. When the screen is less than 600px wide,
make the two columns stack on top of each other instead of next to each other.</p>
<div class="container">
<form action="/action_page.php">
<div class="row">
<div class="col-25">
<label for="fname">First Name</label>
</div>
<div class="col-75">
<input type="text" id="fname" name="firstname" placeholder="Your name..">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="lname">Last Name</label>
</div>
<div class="col-75">
<input type="text" id="lname" name="lastname" placeholder="Your last name..">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="country">Country</label>
</div>
<div class="col-75">
<select id="country" name="country">
<option value="australia">Australia</option>
<option value="canada">Canada</option>
<option value="usa">USA</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="subject">Subject</label>
</div>
<div class="col-75">
<textarea id="subject" name="subject" placeholder="Write something.."
style="height:200px"></textarea>
</div>
</div>
<div class="row">
<input type="submit" value="Submit">
</div>
</form>
</div>
</body>
</html>
Output
Penjelasna
Menggabungkan semua materi forms yang sudah dipelajari menjadi satu form
Automatic numbering with counters
Code
<!DOCTYPE html>
<html>
<head>
<style>
body {
counter-reset: section;
}
h2::before {
counter-increment: section;
content: "Section " counter(section) ": ";
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Untuk memberi daftar nomor dengan CSS Counters
Nesting Counters
Code
<!DOCTYPE html>
<html>
<head>
<style>
body {
counter-reset: section;
}
h1 {
counter-reset: subsection;
}
h1::before {
counter-increment: section;
content: "Section " counter(section) ". ";
}
h2::before {
counter-increment: subsection;
content: counter(section) "." counter(subsection) " ";
}
</style>
</head>
<body>
<h1>HTML tutorials:</h1>
<h2>HTML Tutorial</h2>
<h2>CSS Tutorial</h2>
<h1>Scripting tutorials:</h1>
<h2>JavaScript</h2>
<h2>VBScript</h2>
<h1>XML tutorials:</h1>
<h2>XML</h2>
<h2>XSL</h2>
</body>
</html>
Output
Penjelasan
Memberi daftar nomor yang bersaarang
Header
Code
<!DOCTYPE html>
<html lang="en">
<head>
<title>CSS Website Layout</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
}
<div class="header">
<h1>Header</h1>
</div>
</body>
</html>
Output
Penjelasan
Untuk membuat header dengan CSS
NavBar
Code
<!DOCTYPE html>
<html lang="en">
<head>
<title>CSS Website Layout</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
{
box-sizing: border-box;
}
body {
margin: 0;
}
/* Style the header */
.header {
background-color: #f1f1f1;
padding: 20px;
text-align: center;
}
<div class="header">
<h1>Header</h1>
</div>
<div class="topnav">
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
</div>
</body>
</html>
Output
Penjelasan
Untuk membuat navigation bar dengan CSS
Content
Code
<!DOCTYPE html>
<html lang="en">
<head>
<title>CSS Website Layout</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
{
box-sizing: border-box;
}
body {
margin: 0;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next
to each other */
@media screen and (max-width:600px) {
.column {
width: 100%;
}
}
</style>
</head>
<body>
<div class="header">
<h1>Header</h1>
<p>Resize the browser window to see the responsive effect.</p>
</div>
<div class="topnav">
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
</div>
<div class="row">
<div class="column">
<h2>Column</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sit amet pretium
urna. Vivamus venenatis velit nec neque ultricies, eget elementum magna tristique.
Quisque vehicula, risus eget aliquam placerat, purus leo tincidunt eros, eget luctus quam
orci in velit. Praesent scelerisque tortor sed accumsan convallis.</p>
</div>
<div class="column">
<h2>Column</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sit amet pretium
urna. Vivamus venenatis velit nec neque ultricies, eget elementum magna tristique.
Quisque vehicula, risus eget aliquam placerat, purus leo tincidunt eros, eget luctus quam
orci in velit. Praesent scelerisque tortor sed accumsan convallis.</p>
</div>
<div class="column">
<h2>Column</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sit amet pretium
urna. Vivamus venenatis velit nec neque ultricies, eget elementum magna tristique.
Quisque vehicula, risus eget aliquam placerat, purus leo tincidunt eros, eget luctus quam
orci in velit. Praesent scelerisque tortor sed accumsan convallis.</p>
</div>
</div>
</body>
</html>
Output
Penjelasan
Untuk membuat isi konten
Unequal Content
Code
<!DOCTYPE html>
<html lang="en">
<head>
<title>CSS Website Layout</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
{
box-sizing: border-box;
}
body {
margin: 0;
}
/* Middle column */
.column.middle {
width: 50%;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next
to each other */
@media screen and (max-width: 600px) {
.column.side, .column.middle {
width: 100%;
}
}
</style>
</head>
<body>
<div class="header">
<h1>Header</h1>
<p>Resize the browser window to see the responsive effect.</p>
</div>
<div class="topnav">
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
</div>
<div class="row">
<div class="column side">
<h2>Side</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit..</p>
</div>
</body>
</html>
Output
Penjelasan
Untuk membuat isi konten dengan isi yang berbeda.
Footer
Code
<!DOCTYPE html>
<html lang="en">
<head>
<title>CSS Website Layout</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
{
box-sizing: border-box;
}
body {
margin: 0;
}
/* Middle column */
.column.middle {
width: 50%;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next
to each other */
@media screen and (max-width: 600px) {
.column.side, .column.middle {
width: 100%;
}
}
<div class="header">
<h1>Header</h1>
<p>Resize the browser window to see the responsive effect.</p>
</div>
<div class="topnav">
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
</div>
<div class="row">
<div class="column side">
<h2>Side</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit..</p>
</div>
<div class="footer">
<p>Footer</p>
</div>
</body>
</html>
Output
Penjelasan
Untuk membuat footer
Responsive Web Layout
Code
<!DOCTYPE html>
<html>
<head>
<style>
{
box-sizing: border-box;
}
body {
font-family: Arial;
padding: 10px;
background: #f1f1f1;
}
/* Header/Blog Title */
.header {
padding: 30px;
text-align: center;
background: white;
}
.header h1 {
font-size: 50px;
}
/* Right column */
.rightcolumn {
float: left;
width: 25%;
background-color: #f1f1f1;
padding-left: 20px;
}
/* Fake image */
.fakeimg {
background-color: #aaa;
width: 100%;
padding: 20px;
}
/* Footer */
.footer {
padding: 20px;
text-align: center;
background: #ddd;
margin-top: 20px;
}
/* Responsive layout - when the screen is less than 800px wide, make the two columns
stack on top of each other instead of next to each other */
@media screen and (max-width: 800px) {
.leftcolumn, .rightcolumn {
width: 100%;
padding: 0;
}
}
/* Responsive layout - when the screen is less than 400px wide, make the navigation links
stack on top of each other instead of next to each other */
@media screen and (max-width: 400px) {
.topnav a {
float: none;
width: 100%;
}
}
</style>
</head>
<body>
<div class="header">
<h1>My Website</h1>
<p>Resize the browser window to see the effect.</p>
</div>
<div class="topnav">
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#" style="float:right">Link</a>
</div>
<div class="row">
<div class="leftcolumn">
<div class="card">
<h2>TITLE HEADING</h2>
<h5>Title description, Dec 7, 2017</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco.</p>
</div>
<div class="card">
<h2>TITLE HEADING</h2>
<h5>Title description, Sep 2, 2017</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco.</p>
</div>
</div>
<div class="rightcolumn">
<div class="card">
<h2>About Me</h2>
<div class="fakeimg" style="height:100px;">Image</div>
<p>Some text about me in culpa qui officia deserunt mollit anim..</p>
</div>
<div class="card">
<h3>Popular Post</h3>
<div class="fakeimg"><p>Image</p></div>
<div class="fakeimg"><p>Image</p></div>
<div class="fakeimg"><p>Image</p></div>
</div>
<div class="card">
<h3>Follow Me</h3>
<p>Some text..</p>
</div>
</div>
</div>
<div class="footer">
<h2>Footer</h2>
</div>
</body>
</html>
Output
Penjelasan
Membuat layout website yang responsive
Height/Width example
Code
<!DOCTYPE html>
<html>
<head>
<style>
div {
height: 200px;
width: 50%;
background-color: powderblue;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Mengatur lebar dan tinggi sebuah elemen
Setting max-width
Code
<!DOCTYPE html>
<html>
<head>
<style>
div {
max-width: 500px;
height: 100px;
background-color: powderblue;
}
</style>
</head>
<body>
<div></div>
<p>Resize the browser window to see the effect.</p>
</body>
</html>
Output
Penjelasan
Mengatur lebar maksimum sebuuah elemen
Element Selector
Code
<!DOCTYPE html>
<html>
<head>
<style>
p{
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Digunakan untuk menandai suatu elemen yang akan dimodifikasi dengan lewat elemen
style
CSS id Selector
Code
<!DOCTYPE html>
<html>
<head>
<style>
#para1 {
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Menggunakan selector pada id
CSS Class selector
Code
<!DOCTYPE html>
<html>
<head>
<style>
.center {
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
Output
Penjelasan
Menggunakan selector melalui class
CSS Universal Selector
Code
<!DOCTYPE html>
<html>
<head>
<style>
{
text-align: center;
color: blue;
}
</style>
</head>
<body>
<h1>Hello world!</h1>
Penjelasan
Menggunakan selector dengan universal
Grouping selector
Code
<!DOCTYPE html>
<html>
<head>
<style>
h1, h2, p {
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<h2>Smaller heading!</h2>
<p>This is a paragraph.</p>
</body>
</html>
Output
Penjelasan
Menggunakan selector dengan digrup