为什么反应删除我的班级名称? [英] Why is react removing my class names?
问题描述
我正在学习Reactjs,我正在渲染一个包含一些组件的简单页面。
其中一个组件是:
I'm learning Reactjs, and I am rendering a simple page with some components. One of this components is this:
class Header extends React.Component {
render(){
return (
<header>
<div class="container">
<Logo />
<Navigation />
</div>
</header>
);
}
}
export default Header
我正在使用 Bootstrap CSS 我希望标题内的 div
使用容器的样式
,然而,在构建之后,类已经消失了。
I'm using Bootstrap CSS I want the div
inside the header to use the styles of container
, how ever, after build, the class is gone.
有没有办法强制组件中的属性类?
Is there a way to force the attribute class in the components?
推荐答案
您必须使用 className
属性而不是类
属性,例如:
You have to use the className
attribute instead of the class
attribute, e.g :
class Header extends React.Component {
render() {
return (
<header>
<div className="container">
<Logo />
<Navigation />
</div>
</header>
);
}
}
检查 支持的属性 。
Check the list of Supported Attributes in the documentation.
所有属性都是驼峰式的,属性
class
和for
分别是className
和htmlFor
,以匹配DOM API规范。
All attributes are camel-cased and the attributes
class
andfor
areclassName
andhtmlFor
, respectively, to match the DOM API specification.
这篇关于为什么反应删除我的班级名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!