HTML бүлэг шинж чанар нь HTML элементийг ангилхад хэрэглэнэ
Олон тооны HTML элементүүд нэг анги хуваалцах боломжтой.
Бүлэг(Class) шинж чанарыг ашиглах #
The class attribute is often used to point to a class name in a style sheet.
class загварын хуудсан дээр бүлэгийн нэрийг заахад хэрэглэн
In the following example we have three <div> elements with a class attribute with the value of “city”. All of the three <div> elements will be styled equally according to the .city style definition in the head section:
Дараах жишээнд бид “city” гэсэн утгатай бүлэг(class) шинж чанар бүхий гурван <div> элементтэй байна. Гурван <div>элементийг толгой хэсэгт .city хэв маягийн тодорхойлолтын дагуу адилхан загварчлах болно.
<!DOCTYPE html>
<html>
<head>
<style>
.city {
background-color: tomato;
color: white;
border: 2px solid black;
margin: 20px;
padding: 20px;
}
</style>
</head>
<body>
<div class="city">
<h2>London</h2>
<p>London is the capital of England.</p>
</div>
<div class="city">
<h2>Paris</h2>
<p>Paris is the capital of France.</p>
</div>
<div class="city">
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan.</p>
</div>
</body>
</html> Дараах жишээн дээр бид <span> элемент class attribute with the value of “note”. Both <span> elements will be styled equally according to the .note style definition in the head section:
Дараах жишээнд бид “тэмдэглэл” -ийн утгатай class шинж чанар бүхий хоёр <span> элементтэй байна. <span> элементүүд хоёулаа толгой хэсгийн .noteхэв маягийн тодорхойлолтын дагуу адил тэгш загварчилагдах болно:
<!DOCTYPE html>
<html>
<head>
<style>
.note {
font-size: 120%;
color: red;
}
</style>
</head>
<body>
<h1>My <span class="note">Important</span> Heading</h1>
<p>This is some <span class="note">important</span> text.</p>
</body>
</html> Зөвлөгөө: classшинж чанар нв HTML-ийн бүх элементүүд дээр ашиглаж болно
Санамж: class нь заавал жижиг үсгээр бичигдэнэ.