为什么在html中使用style-attribute? [英] Why is using the style-attribute in html bad?

查看:562
本文介绍了为什么在html中使用style-attribute?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经被告知,以及读取,使用html中的样式属性被认为是坏/斜坡/贫穷的形式。此外,所有呈现特定位应被适当地离散为css和其它部分。我试图理解为什么这是真的。

I have been told, as well as read that using the style attribute in html is considered bad/sloppy/poor form. Further, that all rendering specific bits should be divorced into css and other parts as appropriate. I am trying to understand why exactly this is.

我可以看到为什么你可能想要保持HTML是一个纯粹的语义DOM,说明文档的结构,但对于实际页面,重要的是,页面看起来正确,功能适当。

I can see why you might want to keep the HTML a pure semantic DOM, that speaks about the structure of the document, but for practical pages, the importance is that the page looks right and functions appropriately.

这种分离有更多令人信服的理由吗?

Is there some more compelling reasons for this separation?

推荐答案


  • 关注分离这使得更改样式而不更改标记变得容易,反之亦然。

    • Separation of concerns This makes it easy to replace the styles without changing the markup, or vice versa. Plus you can have one person working on CSS and another working on content

      不要重复自己您可以将样式应用于许多元素,而不必重复它一遍又一遍。较小的页面意味着使用较少带宽的更快的加载时间。

      Don't Repeat Yourself You can apply a style to many elements without having to repeat it over and over. Smaller pages means quicker load times using less bandwidth. Plus it's easier to modify later, because you can change it in one place in one file, instead of many places in many files.

      Cachability

      Cachability If the same style sheet is used on every page of your site, broswers can download it once and then cache it, instead of downloading the styles with the content of every single page. And they won't have to re-download it whenever the content of those pages changes.

      多个版本这很容易,创建您的网站的视觉布局和外观的多个版本,因为你只需要换出样式表文件来改变每个页面的外观。例如,您可以创建一个白标签版本的Web应用程序,您的合作伙伴可以重新皮肤匹配他们的品牌。请参阅 CSS禅花园,了解这种方法的灵活性。

      Multiple Versions It is easy to create multiple versions of the visual layout and appearance of your site, since you just need to swap out the stylesheet file to change the appearance of every page. For instance, you can create a white-label version of a web application which your partners can re-skin to match their brand. See CSS Zen Garden for some great examples of how flexible this approach can be.

      这篇关于为什么在html中使用style-attribute?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆