Ankit Shukla
Ankit Shukla

Reputation: 43

Is it a good practise if I make classes for common css style settings and assign them to html elements?

Here is my code:

style.css

.background-cover{background-size:cover; background-position:center;}
.op-1{opacity:0.1;}
.border-3-solid{border-width:3px; border-color: solid;}
.border-black{border-color:#000;}
.full-width{width:100%;}

index.html

    <div class="full-width background-cover op-1 border-3-solid 
border-black" style="background-image:url('imageurl.png')"></div>

Is using more number of classes per element can be an issue in a long time? Should I create more general utility classes like these or just defined styles for each element and use lesser classes?

Upvotes: 0

Views: 656

Answers (3)

Muhammad Zubair Saleem
Muhammad Zubair Saleem

Reputation: 517

It is a good practice if you want to be UI Designer.

less you code more you learn.

The classes are defined as sets of html page designs which you may want to change quick in future or may be an other team mate wants to deal with that stuff.

Upvotes: 0

Mehraj Khan
Mehraj Khan

Reputation: 977

Adding More classes makes your page execution time slow.so use less classes and group commonly used stylings and properties into a class.

Upvotes: 0

HasilT
HasilT

Reputation: 2609

Using more number of classes can be cumbersome to manage if you're having a large project. What good is that you should group commonly used stylings and properties into a class and later use them on your HTML page, this way your application will have a solid appearance and you can easily modify/edit them in future. In this way, you can also define additional paddings and other small changes to your elements on style sheet by calling them with their id, So your code looks cleaner and easier to read.

Upvotes: 1

Related Questions