开发者

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

Is it better to create a class for a single r开发者_如何学Goule (e.g. float:left;) or apply it using inline style?


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜