为什么反应删除我的班级名称? [英] Why is react removing my class names?

查看:103
本文介绍了为什么反应删除我的班级名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习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 and for are className and htmlFor, respectively, to match the DOM API specification.

这篇关于为什么反应删除我的班级名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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