简体   繁体   English

关于CSS继承,class和className有什么区别?

[英]What's the difference between class and className with respect to css inheritance?

I am exploring the css inheritance in react js. 我正在react js中探索css继承。 I pass in the same object but I got two different results between using class and className. 我传递了相同的对象,但是在使用class和className时得到了两个不同的结果。

Here is the code: https://codesandbox.io/s/olk4xm60v6 (demo.js) 这是代码: https ://codesandbox.io/s/olk4xm60v6(demo.js)

To specify a CSS class, use the className attribute. 要指定CSS类,请使用className属性。 This applies to all regular DOM and SVG elements like <div> , <a> , and others. 这适用于所有常规DOM和SVG元素,例如<div><a>等。

If you use React with Web Components (which is uncommon), use the class attribute instead. 如果您将React与Web组件一起使用(不常见),请改用class属性。

read doc 阅读文件

Styling and CSS 样式和CSS

In ReactJs you are writing JSX not HTML so you must follow the rules of jsx code ReactJs中,您编写的是JSX而不是HTML,因此您必须遵循jsx代码的规则

in jsx if you want to give class to certain tag you need to use className instead of class jsx中,如果您想将class赋予某些标签,则需要使用className而不是class

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

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