AlexBrand
AlexBrand

Reputation: 12429

Which is better: class with single rule or inline style?

Is it better to create a class for a single rule (e.g. float:left;) or apply it using inline style?

Upvotes: 0

Views: 105

Answers (3)

Jason Gennaro
Jason Gennaro

Reputation: 34853

Better to create a class.

  1. You never know when you will want to use that style again. Having it in a class can make it easier to reuse. For instance, an img.right class can be used to float all your images to the right (with the class right).

  2. Inline styles are difficult to override should you want to do so in the future.

  3. Classes on elements make those elements easier to manipulate with javascript and other programming languages.

  4. It keeps you code clean and easy to read, for you and for others.

Upvotes: 3

Guffa
Guffa

Reputation: 700592

The layout should be separated from the content, so you should have the style in the stylesheet.

Upvotes: 3

PeeHaa
PeeHaa

Reputation: 72682

It's never better to use inline styles no matter what for both readability and maintainability.

Same would go for inline JavaScript.

It makes it a lot easier for yourself if you seperate the logic and the view stuff.

Upvotes: 4

Related Questions