Menggunakan CSS
Bertanggung jawab pada bagian penyajian (rendering) CSS adalah sebuah teknologi yang bertujuan untuk memperluas kemampuan HTML. The bad news is, walaupun Microsoft Internet Explorer and Netscape mendukung style sheets, keduanya tidak identik : Tiap browser akan menampilkan kode style sheet yang sedikit perbedaan satu dengan yang lain.
HTML Vs CSS
HTML defines the structure of a document, the organization of text and images and other data into individual elements (via tags). CSS define how these elements are displayed in terms of typography, color, spacing, etc. In basic terms, styles are applied to elements but elements - the content structure - are defined by the markup language.
WHY CSS?
Separation of structure and presentation Simpler more manageable HTML code Finer and more predictable control over presentation Flexible Centralized control of presentation Accessibility Simple syntax
Syntax CSS
Syntax CSS
Kumpulan instruksi dinamakan statements
Bagian Selector, yang mendefinisikan elemen mana yang diberi style Bagian Declaration, yang bertugas memberitahu browser bagaimana menampilkan elemen tadi.
Property value
P { color: blue }
Selector Declaration
Syntax CSS
Aturan CSS
Aturan yang lain Jika ada dua aturan yang berbeda, misalnya: P ( color: red } P { background-color: white } keduanya dapat disatukan menjadi P { color: red ; background-color: white } ataudapat pula menggabungkan beberapa elemen, seperti: H1, H2, H3, H4, H5, H6 { color: green } Catatan: Jika akan menggabungkan elemen gunakan tanda koma , . Jika akan menggabungkan beberapa deklaration gunakan tanda titik koma ;
Atribut CLASS
Contoh pendeklarasian
Pendeklarasian
.punk { color: lime; background: #ff80c0 } P.warning { font-weight: bolder; color: red;
background: white }
Cara pemanggilan:
<H1 CLASS=punk>Proprietary Extensions</H1> <P CLASS=warning>Many proprietary extensions can have negative side-effects, both on supporting and non-supporting browsers... </p>
Atribut ID
Contoh pendeklarasian
Pendeklarasian #wdg97 { font-size: larger }
Cara pemanggilan:
<P ID=wdg97>Welcome to the Web Design Group!</P>
Class Vs ID
The ID attribute of an HTML tag is intended solely to provide a unique identifier.
no two elements within a document (web page) can have the same ID. Anytime you add an ID attribute to a tag, its value should be different from that of any other element's ID on the page, even if they have different tag names. So a style rule with an ID selector can, at most, only apply to a single element on a page. Pada pendefinisian suatu ID, Suatu elemen hanya berisi satu ID
The class selector, on the other hand, can be applied to several elements on a page. You can even make rules using the same class name with different tag names. Sebuah elemen dapat berisi beberapa class
The CLASS attribute was specifically designed to allow authors to assign styles to elements
Inlining Style
Contoh pendeklarasian:
<P STYLE="color: red; font-family: 'New Century Schoolbook', serif"> This paragraph is styled in red with the New Century Schoolbook font, if available.</P>
Elemen SPAN
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <HTML> <HEAD> <TITLE>Example of SPAN</TITLE> <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> <STYLE TYPE="text/css" MEDIA="screen, print, projection"> <!- .firstwords { font-variant: small-caps } --> </STYLE> </HEAD> <BODY> <P> <SPAN CLASS=firstwords>The first few words</SPAN> of a paragraph could be in small-caps. Style may also be inlined, such as to change the style of a word like <SPAN STYLE="font-family: Arial"> Arial</SPAN>. </P> </BODY> </HTML>
Elemen DIV
Contoh pendeklarasian:
<DIV CLASS=note> <H1>Divisions</H1> <P>The DIV element is defined in HTML 3.2, but only the ALIGN attribute is permitted in HTML 3.2. HTML 4.0 adds the CLASS, STYLE, and ID attributes, among others.</P> <P>Since DIV may contain other block-level containers, it is useful for marking large sections of a document, such as this note.</P> <P>The closing tag is required.</P> </DIV>
Inheritance
Some style properties are inherited by default. It pays to think of some (X)HTML elements as parents, and the elements they contain as children. A parent owns a child, and passes what he or she knows down to the child. These include properties such as color, font and text-align.
misalnya:
Hasilnya:
Cascade
Through Varying Methods of Application
1. The browser performs the inline rule first, and then 2. looksto perform any other rules embedded in the <head>, and finally 3. looks to any external files to complete its understanding of the CSS you created.
More Than Doodles (http://doodles.cssmastery.com) uses floats for the whole layout. All images and columns are floated to some degree.
Positioning
MODEL BOX
Tipe BOX
Box dibagi dalam dua tipe: block dan inline.
Block boxes are generated by elements such as P, DIV or TABLE. Inline boxes are generated by tags such as B, I or SPAN and actual content like text and images.
Float
Konsep float adalah kunci untuk membuat layout menggunakan CSS. Floats allow you to rebel against the linear nature of the flow of elements on a page. Tanpa float, setiap elemen akan diletakkan dibawah elemen diatasnya (sebelumnya), dan halaman akan panjang ke bawah. Tidak akan ada kolom dan tidak ada gambar sebaris, dan kita akan masih menggunakan tabel untuk layout. Ketikan akan memberikan float pada elemen, elemen akan menjadi sebuah block-level element yang kemudian dapat diposisikan ke kiri atau kanan dalam satu garis yang sama. Float kebanyakan digunakan untuk meletakkan gambar di konteks, membuat kolom dan umumnya menggiring designer untuk berfikir secara horisoltal.
Float Properties
1. Float:left 2. Float:right 3. float:none default
The Problem
That the containing <div> (container) doesnt recognize the float, and as a result it is not expanding vertically to contain the <image_float> element, only the now-less-tall paragraph. It must therefore be a good time to look at clearing floats.
Clearing Floats
Adalah cara untuk menghilangkan pengaruh float. Empat pilihan untuk clearing float:
clear:left clear:right clear:both clear:none
Without clearing the paragraph, the text sits right up against the gray box.
The gray box is floated left, and the paragraph is cleared left.
Clar:both
By specifying clear:both, the element is moved below all floating elements, regardless of whether they are floated left or right. In this example, the box is floated left, but the clear property for the paragraph is given the both value.
With or without clearing the float, if the nonfloated element (the paragraph) is taller than the floated element, the container will behave properly.
Position
Empat tipe positioning :
Static positioning Absolute positioning Fixed positioning to be placed in relation to the actual browser window Relative positioning
Static positioning
With either no position whatsoever or position:static declared, the paragraph and image are arranged inside the container in their default (static) positions
Relative positioning
The position relates not to any parent element or to the browser window, but specifically to the properties of the element itself.
Absolute positioning
An absolutely positioned element is designed to take its point of reference from the nearest positioned element.
Fixed positioning
As a result of this change, the images position will appear to be the same as in the absolutely positioned example. The real surprise comes when you scroll the page.
Tipe Layout
Ada beberapat tipe layout: 1. fixed width using static width measurements, typically pixels. A fixedwidth layout does not stretch to fill the browser window, and remains its set width whatever you do to it. 2. Liquid expands and contracts to fill the browser window. Widths declared using percentage measurements 3. Elastic - - > contoh 4. variable fixed width - - > contoh
Selamat belajar
Layout 2 Kolom
Note
Remember that every time you create a new column <div>, you also create a new parent element for any elements it contains. This means that you can be even more specific with your CSS and how you target certain elements using contextual selectors.
Tugas
Create two different CSS (one internal and one external) for the Web page developed in Homework. The two CSS should contain different styles for at least the:
Background. Text. Font. Classes. IDs.