admin管理员组

文章数量:1208155

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

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?

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

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?

Share Improve this question edited Jul 28, 2018 at 17:48 Zakaria Acharki 67.5k15 gold badges78 silver badges105 bronze badges asked Jan 30, 2016 at 15:45 PabloPablo 10.6k18 gold badges59 silver badges80 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 28

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.

All attributes are camel-cased and the attributes class and for are className and htmlFor, respectively, to match the DOM API specification.

本文标签: javascriptWhy is react removing my class namesStack Overflow