标记中的多个类 - 会降低性能吗? [英] Multiple classes in markup - will it slow down performance?

查看:79
本文介绍了标记中的多个类 - 会降低性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在一家大酒店连锁店的网站上工作,在css中,他们对每一种可想象的情况都有一个预先存在的类。

So I'm working on a site for a major hotel chain and in the css they have a preexisting class for every imaginable situation.

我正在编辑页面中添加超过100个

实例的代码:

I'm editing a page, adding over 100

instances with the code:

<p class="pad-b10 pad-t15 margin-b5 border-bottom-black">

这适用于底部的10像素填充,顶部15像素填充,底部和底部有一个黑色边框。

Which applies a 10px padding to the bottom, a 15px padding to the top, a 5px margin to the bottom and a black border underneath.

我的问题是,创建一个包含所有这些参数的类更有意义吗?

My question is, does it make more sense to create one class that has all of these parameters included? I don't see very many custom classes in the rest of the css.

感谢

推荐答案

在Mozilla的实现中(也可能是其他的),对于每个元素,CSS引擎通过样式规则搜索匹配。引擎从右到左评估每个规则,从最右边的选择器(称为键)开始,并移动每个选择器,直到找到匹配或丢弃规则。 (selector是应该应用规则的文档元素。)

In Mozilla's implementation (and probably others as well), for each element, the CSS engine searches through style rules to find a match. The engine evaluates each rule from right to left, starting from the rightmost selector (called the "key") and moving through each selector until it finds a match or discards the rule. (The "selector" is the document element to which the rule should apply.)

在这种情况下,它非常值得拥有单一样式元素,只搜索一个键(css类名),inturn会提高性能。

In this scenario its very much worthy to have single style element so that the browser need to search only one key(css class name) which inturn increases the performance.

这篇关于标记中的多个类 - 会降低性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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