Selectors — class and id · Pemilih — class dan id
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · Halaman ini memerlukan browser terbaru (dengan dukungan SharedArrayBuffer). Silakan perbarui Chrome, Edge, Firefox, atau Safari ke versi terbaru.
English
Three kinds of selector
- A selector says which elements a rule changes.
- By tag:
p { ... }changes every<p>. - That is the kind you used last lesson.
Bahasa Indonesia
Tiga jenis selector
- Selector mengatakan elemen mana yang diubah oleh aturan.
- Berdasarkan tag:
p { ... }mengubah semua<p>. - Itu adalah jenis yang Anda gunakan pada pelajaran terakhir.
English
By class and by id
- By class:
.note { ... }changes every element withclass="note". A dot.means class. - By id:
#title { ... }changes the one element withid="title". A hash#means id. - A class can be on many elements; an id should be on one.
Bahasa Indonesia
Oleh kelas dan oleh id
- Oleh kelas:
.note { ... }mengubah setiap elemen denganclass="note". Titik.berarti kelas. - Oleh id:
#title { ... }mengubah satu elemen denganid="title". Hash#berarti id. - Kelas dapat ada pada banyak elemen; id seharusnya ada pada satu.
<style>
.note { color: green; }
#title { color: purple; }
</style>
<h1 id="title">My page</h1>
<p class="note">This is a note.</p>
<p>This is normal.</p>
English
Common mistakes
- A class selector starts with
., an id selector with#. - Reuse a class on many elements; an id appears once per page.
Bahasa Indonesia
Kesalahan umum
- Selector kelas dimulai dengan
., selector id dengan#. - Gunakan ulang kelas pada banyak elemen; id muncul sekali per halaman.
English
Now you try
- Match the dot
.to a class, and the hash#to an id. - Style a class, then style an id.
Bahasa Indonesia
Sekarang Anda coba
- Cocokkan titik
.ke kelas, dan hash#ke id. - Style kelas, lalu style id.
Style the note. Add a rule for the note class: .note { color: green; } (a dot means class). · Gayakanote. Tambahkan peraturan untuk kelas note: .note { color: green; } (titik bermaksud kelas).
Style the title. Add a rule for the title id: #title { color: purple; } (a hash means id). · Gayakan tajuk. Tambahkan peraturan untuk ID title: #title { color: purple; } (tanda pagar bermaksud ID).