简体   繁体   English

引导程序安装在 ReactJS 应用程序中,但没有样式

[英]Bootstrap installed in ReactJS app but no styling

I am new in ReactJS我是 ReactJS 的新手

I have created a child component called footer and also installed Bootstrap package but not receiving any style in footer.我创建了一个名为 footer 的子组件,还安装了 Bootstrap package 但在页脚中没有收到任何样式。

Code App.js --代码 App.js --

import React, { Component }from 'react';
import './App.css';
import Header from './components/header';
import Footer from './components/footer';

class App extends Component {
    render() {
        return (
            <div>
                <Header />
                <Footer />
            </div>
        );
    }
}

export default App;

Footer.js under components folder组件文件夹下的 Footer.js

import React from 'react';

const Footer = () => {

    return (
        <footer className="page-footer font-small blue">
            <div className="footer-copyright text-center py-3">© 2019 Copyright:
                <a href="http://www.google.co.uk/">Test.com</a>
            </div>
        </footer>
    );
};

export default Footer;

index.js -- index.js——

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import 'bootstrap/dist/css/bootstrap.min.css';

ReactDOM.render(<App />, document.getElementById('root'));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
serviceWorker.register();

But there is no styling in footer.但是页脚中没有样式。

Any help is highly appreciated.非常感谢任何帮助。

Your code looks fine.你的代码看起来不错。 Stop your running code and restart again it will work.停止正在运行的代码并重新启动它会工作。 first time of installation of bootstrap required re-render from start.第一次安装引导程序需要从头开始重新渲染。

Well, the problem is that you don't import bootstrap properly, do you have import errors in your console?好吧,问题是您没有正确导入引导程序,您的控制台中是否有导入错误?

import 'bootstrap/dist/css/bootstrap.css';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';

try to import by one of i written above.尝试通过上面写的我之一导入。

In your app.css import bootstrap.css like this在你的 app.css 导入 bootstrap.css 像这样

import 'bootstrap/dist/css/bootstrap.css';

Then restart your server然后重启你的服务器

That simply means you did not correctly import bootstrap, i dont know how your code is structured so i would suggest you use the cdn version below and link it in your index.html file.这仅仅意味着您没有正确导入引导程序,我不知道您的代码是如何结构的,所以我建议您使用下面的 cdn 版本并将其链接到您的 index.html 文件中。

<link

rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" /> rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" 完整性="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" />

this means you have to online everytime you use it.这意味着您每次使用它时都必须在线。 Another option i would suggest is that you use reactstrap which would be easier for you as a beginner.我建议的另一个选择是您使用 reactstrap,这对初学者来说会更容易。 install by using npm install --save reactstrap and then you can use it any component you want.使用 npm install --save reactstrap 安装,然后您可以使用任何您想要的组件。 you google the documentation for more details.你谷歌文档以获取更多详细信息。

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

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