CodeClerks

What is a class?



Enter a reason for deleting this comment

What is a class?

In reference to a CSS file, what is a class?

Comments

Please login or sign up to leave a comment

Join
Alast

A class is essentially an object.

.class {

}


That would result in nothing, but if you were to add a background-color or anything, then that object will turn into something useful for your website. That being said - classes do not have to contain any visual aspects. They can be used to wrap other classes to ensure everything fits nicely together when resizing your screen.



Enter a reason for deleting this comment

ankitagupta339

Class is used when we want to write properties like text align, color width etc.



Enter a reason for deleting this comment

jakemadness

Some people don't realize a CSS class is used for styling more than one HTML element in your page, a CSS id can be placed on only one HTML element in your page otherwise it will be marked as invalid by w3 validator many people make this mistake What is a class?

Valid:


<style type="text/css">
.class
{
   color: #222;
}
</style>
<span class="class">first element</span>
<span class="class">second element</span>
 


InValid:

<style type="text/css">
#id
{
   color: #222;
}
</style>
<span id="id">first element</span>
<span id="id">second element</span>
 



Enter a reason for deleting this comment

AjayPrasad

In the CSS, a class selector is a name preceded by a full stop (“.”). You can also define your own selectors in the form of class.
.class1 {
color: red;
font-weight: bold;
}
The HTML refers to the CSS by using the attributes class
<p class="class1">This is class1 selector of class attribute in Paragraph tag</p>



Enter a reason for deleting this comment