Random characters in CSS class names

被刻印的时光 ゝ 提交于 2021-02-18 12:22:10

问题


I have noticed one thing. On some sites such as tray.io, asana, fb etc They have random characters in css class names when you inspect them for example:

<header class="Header_XSDsdksdXKkSDD">..</Header>

Why are these characters generated and how are they generated?

Thanks.


回答1:


Those class names or identifiers are probably generated by the engine that produces the page output.

If you want to add a style to a particular element, you want a unique class for it - the easiest way is to generate some pseudo-random identifier.




回答2:


These are probably hash string of a technology similar to CSS Modules.

The main idea is that you use a tool that reads the CSS files and makes unique classes for your different "views". Doing this separates the CSS files per HTML file / template / JSX or whatever your setup is.

If you follow the idea behind it, you can easily achieve more scalable setup of your code, because it allows you to use global and local class names. This means that you will not rely on the "cascading" feature of the CSS to propagate any styles.



来源:https://stackoverflow.com/questions/38942184/random-characters-in-css-class-names

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