Still remember the first part of the lesson that CSS syntax in writing is a selector. In the examples in the previous lesson, you see the use of HTML tags as a selector.
Suppose you create the CSS code for <h1>. Now what if you want to format <h1> with color / different properties? Suppose, you want to tag in the left column <h1> blue while <h1> black in the middle column.
For cases like this, you can use the selector and the ID selector Class.
Class Selector
Class selector is merging some of the properties that are used more than once.
How Writing Class Selector :
. names-class {property: value;}To paste into the HTML tag class :
taghtml.nama-class {Property:value;}Note the dot at the beginning of each class name. If you want to use a class selector outside your HTML code using class=nama-class> <div tag and ends with the tag </ div>.
example :
Writing CSS code :
.tengah {text-align:center;}Use of CSS code
p.tengah {color:red;}
h1.kiri {color:blue;}
h1.tengah {color:black;}
<div class= Center >
<p> central text will be colored red. </ p>
<h1> H1 tag turns black middle </ h1>
</ div>
<h1 class=kiri> left the H1 tag will be blue </ h1>
Teks tengah akan berwarna merah.
Tag H1 tengah akan berwarna hitam
Tag H1 kiri akan berwarna biru
ID Selector
ID Selector is similar to the Class selector. To distinguish it, use ID selector to format part appears only once in a single web page, for example, to format the section menu / sidebar.
How to write ID Selector :
#nama-ID {property:value;}To attach ID tag selector in HTML :
taghtml#nama-ID {Property:value;}Note the # sign at the beginning of each name ID. If you want to use a class selector outside your HTML code using id=nama-ID> <div tag and ends with the tag </ div>.

Post a Comment