Inline styles vs styles in CSS

前端 未结 10 1736
孤城傲影
孤城傲影 2020-12-11 22:53

I know placing all your styles in a CSS file is the best thing to do as it is a lot neater.

But does it REALLY matter if the styles are inline or i

10条回答
  •  时光说笑
    2020-12-11 23:45

    Some thoughts from one with experience, rather than a 'purist':

    Storing all styles, for a large application, in one CSS file is not maintainable. You'll have perform a text search of the file to find the style you're looking for, or scroll a lot, and there's a higher chance that you'll overlook related styles when making an update.

    If certain styles are particular to a page, not globally used, it is more maintainable to keep them in a style tag within the head tag.

    Deep CSS inheritance hierarchies are also not maintainable. These are much, much worse than inline styles! The CSS language itself does a poor job of applying styles to many elements in more complex structures. Consider lesscss, sass, or even jQuery for more than basic application of styles.

    Lots of developers use HTML for presentation, mostly DIVs, when they think they are doing the right thing, or lecturing others. Some example above!

提交回复
热议问题