Use duplicate class name on an element?

戏子无情 提交于 2019-12-01 23:24:48

问题


I found that there are many frameworks will check the duplicate class name before adding the new class name on the element that i think will slow down the performance.

Is there any problems while the element has duplicate class name?

It will also apply the CSS class without conflict while the duplicate class name is in used.

<div class="aa bb cc aa"></div>

Is it OK to add a class name simply just like elem.className += ' ' + 'aa ee', even the element has duplicate class name?


回答1:


There is nothing "wrong" with having a duplicate class name, it's just redundant. There's probably a small performance impact, but that'll only really make much difference if you have a lot of duplication.

Also, preventing duplicates just helps to keep things tidy.




回答2:


Semantic UI heavily uses attribute selectors

like here

.ui.grid [class*="left floated"].column {
  margin-right: auto;
}
.ui.grid [class*="right floated"].column {
  margin-left: auto;
}

If you want margin-left and margin-right to have the auto value, you must have a duplicate of the class floated (ex. <div class="left floated right floated">Lorem</div>)



来源:https://stackoverflow.com/questions/10050851/use-duplicate-class-name-on-an-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!