0
Class
What exactly is the function of Class in HTML?
3 RĂ©ponses
+ 10
That is a style definition, a CSS style definition. CSS defines sets of rules to describe how things should look, and (sort of) behave on your web page.
CSS uses 2 distinct rules for styling your element, it uses "id" to define a style for a single element, and "class" for multiple elements
Think of students in some school, CSS is like the headmaster, when headmaster says "all students wear ties, and black shoes" all the students shall abide, as long as they are classified as students they must follow what headmaster says.
The same is for id, take a specific lesson (math for example) if the headmaster says "math is our priority" then the math lesson will be prioritized, amongst other lessons.
Hth,
+ 3
a class in html allows you to add a particular style more than once using the same name
you can define a class as
.cgreen
{
color : green;
/*this makes the text green*/
}
now use it in your elements like
<p class="cgreen">
the meadow
</p>
<p class="cgreen">
grassland
</p>
it simplifies your task, write once use everywhere
+ 1
The HTML class attribute makes it possible to define equal styles for elements with the same class name.