Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When a specific css style is very often used, should it be a own class? [closed]

Tags:

html

css

When I need very often a specific style like float: left is it better to make a own class or put this style in every class where it is needed?

Here is a example page for what I mean.

JS-Fiddle Example

Is it good how the class left is used? Or would it be better when I put every float: left style into the other classes?

like image 451
MORHERO Avatar asked Dec 17 '25 20:12

MORHERO


1 Answers

The things to consider are readability and repeating yourself.

Readability:

Having a left class with the only rule as float: left will help to make your HTML more readable. Because whenever someone see that class on an element, they know it will be floated left. So in that way it improves readability.

DRY:

With CSS the old adage of "don't repeat yourself" is almost impossible to adhere to, but I think it should still be considered. In this case you should compare. How many times will I add float: left in my CSS? versus How many times will I add class='left' in my HTML?

I would note that most CSS frameworks use utility classes like .left{float:left;}

like image 187
Dan Avatar answered Dec 20 '25 11:12

Dan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!