Rabu, 22 Agustus 2012

Perbedaan Selector ID dan Class pada CSS

Hi Sobat saya mau berbagi pengetahuan nih tentang perbedaan selector ID dan Class pada CSS, tapi kali ini aku minta maaf kalo artikel nya berbahasa inggris cz ini aku abis copy dari sebuah forum luar, dan aku lupa tidak mereferensikan link nya disini, jika terdapat kesulitan dalam menterjemahkannya, silakan anda terjemahkan dengan google translate di atas atau di sini http://translate.google.com 
harap maklum ^^  Thx!

Oke here we go...

  What is the difference between "#" and "." when declaring a set of styles for a particular element? Here are two examples.

.selector {

#selector {

Yes, they are different...

# is an id selector, used to target a single specific element with a unique id, but . is a class selector used to target multiple elements with a particular class. To put it another way:

    #foo {} will style the single element declared with an attribute id="foo"
    .foo {} will style all elements with an attribute class="foo" (you can have multiple classes assigned to an element too, just separate them with spaces, e.g. class="foo bar")

Typical uses

Generally speaking, you use # for styling something you know is only going to appear once, for example, things like high level layout divs such sidebars, banner areas etc.

Classes are used where the style is repeated, e.g. say you head a special form of header for error messages, you could create a style h1.error {} which would only apply to <h1 class="error">

Another aspect where selectors differ is in their specificity - an id selector is deemed to be more specific than class selector. This means that where styles conflict on an element, the ones defined with the more specific selector will override less specific selectors. For example, given <div id="sidebar" class="box"> any rules for #sidebar with override conflicting rules for .box
Learn more about CSS selectors

See Selectutorial for more great primers on CSS selectors - they are incredibly powerful, and if your conception is simply that "# is used for DIVs" you'd do well to read up on exactly how to use CSS more effectively.

 Semoga sobat bisa understood sama artikel di atas  =P 


0 komentar:

Posting Komentar

Komentar anda tidak boleh mengandung unsur:
1.Penghinaan, Rasis dan Pelecehan
2.Spamming (Spam Comments)
3.Link Iklan, ads etc
Terima Kasih.

Jika ada request ato laporan tentang :
1.Request Software atau Tutorial
2.Bad Link & Re-active link (akibat broken link)
Silakan comment di bawah atau kirim pesan ke saya via facebook >> Akunku : Adhieresthenes Hier Banu Arfakhshad