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.
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 tofloat
all your images to the right (with the class right).Inline styles are difficult to override should you want to do so in the future.
Classes on elements make those elements easier to manipulate with javascript and other programming languages.
It keeps you code clean and easy to read, for you and for others.
精彩评论