inf104: web design dasar pemrograman web dengan...

Post on 11-Aug-2019

230 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

INF104: WEB DESIGN

Dasar Pemrograman Web

dengan CSS

Dosen: Wayan Suparta, PhD

Pertemuan 5 & 6:

Pendahuluan Definisi

• Cascading Style Sheets(CSS) adalah suatu teknologi yang digunakan untuk

memperindah halaman website (situs), dengan CSS kita dapat dengan

mudah mengubah keseluruhan warna dan tampilan yang ada disitus kita

sekaligus memformat ulang situs kita.

• CSS ini telah distandarkan oleh World Wide Web Consortium (W3C) untuk

digunakan diweb browser.

Keuntungan CCS

• Dapat di-update dengan cepat dan mudah, karena kita cukup

mendefinisikan sebuah style-sheet global yang berisi aturan-aturan

CSS tersebut untuk diterapakan pada seluruh dokumen-dokumen

HTML pada halaman situs kita.

• User yang berbedadapat mempunyai style-sheet yang berbeda pula. • Ukuran dan kompleksitas document code dapat diperkecil.

CSS Secara Umum ada tiga bagian yaitu

• Selector (elemen yang akan didefinisikan)

• Properti (atribut yang akan diubah)

• Value (Nilai)

Bentuk Umum :

Selector{property: value}

Perintah CSS terdiriatas 2 komponen, yakni Selector & Declaration.

– Selector berfungsi untuk memberitahu browser bahwa pada elemen mana rule CSS diterapkan.

– Selector dapat berupa elemen HTML, selector class atau selector id.

– Declaration merupakan aturan CSS yang diterapkan, terdiri atas property dan value.

Struktur Dasar CSS

External Style Sheet

Bentuk :

<link rel=“stylesheet” type=“text/css” href=“css_files.css”>

dimana :

• <link, merupakan tag pembuka diakhiri dengan tanda “>”

• rel=“stylesheet”, menerangkan halaman ini akan dikenai efek style sheet

• type=“text/css”, file yang dipanggil berupa css

• href=“css_files.css”, alamat dokumen stylesheet yang dipanggil

Internal Style Sheet

Bentuk umum :

<style type=“text/css”>

…definisi style…

</style>

Struktur CSS

Lihat Tutorial CSS

https://www.w3schools.com/css/default.asp

Aturan Penulisan CSS (External Style)

Grouping

CSS Class Selector

CSS Class Selector

CSS ID Selector

Class ID Selector

CSS Dimension

CSS Padding : Contoh

CSS Float

Contoh-Contoh

Save: Prak_CSS01.html

Contoh-Contoh

Save: Prak_CSS02.html

<html>

<head>

<style type = “text/css”>

.header {

width:900px;

height:50px;

border: 1px solid #640404;

}

.headerLeft {

width:400px;

background-

color:#CCCCCC;

height:50px;

float:left;

text-align:center;

}

.headerRight {

width:450px;

background-

color:#999999;

height:50px;

float:right;

text-align:center;

}

</style>

</head>

<body>

</body>

</html>

Contoh-Contoh

Save: Prak_CSS03.html

<html>

<head>

<title>121411091-SYAIFUL</title>

<style>

</style>

</head>

<body>

<div id="batas">

<div id="head">

<center><h1>City Gallery</h1></center>

</div>

<div id="sideleft">

<ul id="hv">LONDON</ul>

<ul id="hv">PARIS</ul>

<ul id="hv">TOKYO</ul>

</div>

<div id="content">

<h2>LONDON</h2>

<p>London is the capital city of England.

If is the most populous city in the United

Kingdom, with a metropolitan area of over

13 million inhabitants.</p>

<p>Standing on the River Thames,

London has been a major settlement for

two millennia, its history going back to its

founding by the Romans, who named it

Londinium.</p>

</div>

<div id="foot">

<center><strong><u>LONDON</u></str

ong></center>

</div>

</div>

</body>

</html>

LATIHAN5 (Praktikum)

1. Tuliskan program CSS dengan hasil tampilan seperti berikut:

Save: Latihan_CSS5.html

INF104: WEB DESIGN

Pemrograman dengan CSS

Lanjutan

Dosen: Wayan Suparta, PhD

Pertemuan 5 & 6:

CSS Box Model

1. CSS Box Model

https://www.w3schools.com/css/css_boxmodel.asp

2. CSS Margin

3. CSS Table <!DOCTYPE html>

<html>

<head>

<style>

table, th, td {

border: 1px solid black;

}

</style>

</head>

<body>

<h2>Add a border to a table:</h2>

<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>

https://www.w3schools.com/css/tryit.asp?filename=trycss_table_fancy

4. CSS Pseudo-Class

• Berfungsi untuk memberikan efek yang

berbeda pada sebuah selektor.

• Biasanya digunakan untuk link/anchor

• Property:

• Contoh:

a:hover

{

color:red;

text-decoration:underline;

}

• Perhatikan contoh berikut:

<!DOCTYPE html>

<html>

<head>

<style>

/* unvisited link */

a:link {

color: red;

}

/* visited link */

a:visited {

color: green;

}

/* mouse over link */

a:hover {

color: hotpink;

}

/* selected link */

a:active {

color: blue;

}

</style>

</head>

<body>

<p><b><a href="default.asp" target="_blank">This is a

link</a></b></p>

<p><b>Note:</b> a:hover a:hover MESTI datang setelah a:link dan a:visited dalam definisi CSS agar dapat efektif. </p>

<p><b>Note:</b> a:active MUST come after a:hover in

the CSS definition in order to be effective.</p>

</body>

</html>

Ouputnya:

5. CSS Image Gallery

<html>

<head>

<style>

div.gallery {

margin: 5px;

border: 1px solid #ccc;

float: left;

width: 180px;

}

div.gallery:hover {

border: 1px solid #777;

}

div.gallery img {

width: 100%;

height: auto;

}

div.desc {

padding: 15px;

text-align: center;

}

</style>

</head>

<body>

<div class="gallery">

<a target="_blank" href="img_5terre.jpg">

<img src="img_5terre.jpg" alt="Cinque

Terre" width="600"height="400">

</a>

<div class="desc">Add a description of the image

here</div>

</div>

https://www.w3schools.com/css/css_image_gallery.asp

<div class="gallery">

<a target="_blank" href="img_forest.jpg">

<img src="img_forest.jpg" alt="Forest" width="600"height="400">

</a>

<div class="desc">Add a description of the image here</div>

</div>

<div class="gallery">

<a target="_blank" href="img_lights.jpg">

<img src="img_lights.jpg" alt="Northern Lights" width="600"height="400">

</a>

<div class="desc">Add a description of the image here</div>

</div>

<div class="gallery">

<a target="_blank" href="img_mountains.jpg">

<img src="img_mountains.jpg" alt="Mountains" width="600"height="400">

</a>

<div class="desc">Add a description of the image here</div>

</div>

</body>

</html>

Outputnya:

6. CSS Default Button

<!DOCTYPE html>

<html>

<head>

<style>

.button {

background-color: #4CAF50;

border: none;

color: white;

padding: 15px 32px;

text-align: center;

text-decoration: none;

display: inline-block;

font-size: 16px;

margin: 4px 2px;

cursor: pointer;

}

</style>

</head>

<body>

<h2>CSS Buttons</h2>

<button>Default Button</button>

<a href="#" class="button">Link Button</a>

<button class="button">Button</button>

<input type="button" class="button"

value="Input Button">

</body>

</html>

https://www.w3schools.com/css/tryit.asp?filename=trycss_buttons_basic

7. CSS Running Text <HTML>

<head>

<title>usage marquee</title>

</head>

<body>

<p>Example of using marquee.</p>

<div align="center">

<marquee

direction="left"

loop="7"

scrollamount="1"

scrolldelay="2"

behavior="alternate"

width="60%"

bgcolor="#ff3424"

>Latest news !. Latest news !.Latest news !.Latest news !.

</marquee>

</div>

</body>

</html>

8. CSS Website Layout

https://www.w3schools.com/css/tryit.asp?filename=trycss_website_layout_navbar

<!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;

}

/* Style the top navigation bar */

.topnav {

overflow: hidden;

background-color: #333;

}

/* Style the topnav links */

.topnav a {

float: left;

display: block;

color: #f2f2f2;

text-align: center;

padding: 14px 16px;

text-decoration: none; }

/* Change color on hover */

.topnav a:hover {

background-color: #ddd;

color: black;

}

</style>

</head>

<body>

<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>

LATIHAN6 (Praktikum)

2. Tuliskan program CSS dengan hasil tampilan dengan memebri link seperti gambar berikut:

Save: Latihan_CSS6.html

TUGAS 2 (6 hari) Buatlah sebuah webpage news papers, minimal seperti gambar di bawah dengan CSS.

Berilah nama file dengan nama Anda: News_NIM_Nama4huruf (misalkan:

04206063_Arya_Tugas2.html). Kirim ke link:

https://new.edmodo.com/groups/webdesign-29276210

top related