简体   繁体   English

CSS:内联和外部样式表的平衡?

[英]CSS: inline and external stylesheet balance?

I am using SEO analyzer, and it tries to make me crazy. 我正在使用SEO分析器,它试图使我发疯。 It says that the page has inline css. 它说页面有内联css。 I have external css, which lists reused styles, but I do not see value to put once-used "style" stuff into this sheet so I leave them in html. 我有外部css,其中列出了重复使用的样式,但是我看不到将曾经使用过的“样式”内容放入此工作表的价值,因此我将其保留在html中。 I particularly curious about width and height css properties, which I define for images. 我特别想知道我为图像定义的width和height css属性。 Why this SEO analyzer does not check for uniqueness of styles? 为什么此SEO分析器不检查样式的唯一性?

The value in using groups of styles that you only use once is that you may find later on that you may have to use it more than once. 使用仅使用一次的样式组的价值在于,您可能稍后会发现可能必须多次使用它。 If you already have the appropriate set of rules, it's a simple matter of using the stylesheet selector. 如果您已经有了适当的规则集,则只需使用样式表选择器即可。 It also makes it easier to update later on since the styles are in a canonical place in the CSS rather than a random place in the html. 由于样式在CSS中的规范位置而不是html中的随机位置,因此这也使以后更容易更新。

As for width/height on <img> , these should be done via the attributes rather than style , and the analyzer should not complain about that -- in fact it should encourage you to use those attributes. 至于<img>上的width / height,这些应该通过属性而不是style来完成,并且分析器不应对此有所抱怨-实际上,它应该鼓励您使用这些属性。

There is probably a lot of subjectivity in the SEO analyzer, but one of the key points of SEO is minimizing download size. SEO分析器中可能有很多主观性,但是SEO的关键点之一是最小化下载大小。 Removing style attributes does this. 删除style属性可以做到这一点。 It does increase the size of the CSS file, though, but probably not by as much. 它确实会增加CSS文件的大小,但可能不会增加太多。 I'm not sure what effect that has. 我不确定会有什么影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM