ReactBootstrap导入bootstrap.min.css后导航栏与轮播图宽度异常求助
我最近在用ReactBootstrap搭建个人React站点,导航栏(Navbar)和轮播图(Carousel)都是用ReactBootstrap的组件实现的,页脚组件Footer.js则是基于MdBootstrap开发的。
原本页面布局一切正常,直到我在Footer.js里导入了bootstrap.min.css之后,突然发现Carousel.jsx和CustomNavbar.jsx的组件不再是全屏宽度了——原本应该撑满整个视口的元素,现在左右两边出现了明显的留白,完全破坏了之前的布局效果。
我猜测是Footer组件里导入的bootstrap样式,覆盖了index.html中已经全局引用的同一份bootstrap文件,但试了移除其中一处导入、调整导入顺序等方法都没解决这个冲突,实在摸不着头脑,恳请各位大佬帮忙分析下问题出在哪,以及怎么修复这个样式冲突?
Footer.js 代码
import React from 'react'; import 'bootstrap/dist/css/bootstrap.min.css'; // 怀疑是这行导入引发了样式冲突 import { MDBFooter, MDBContainer, MDBRow, MDBCol, MDBIcon } from 'mdb-react-ui-kit'; export default function Footer() { return ( <MDBFooter bgColor='light' className='text-center text-lg-start text-muted'> <section className='d-flex justify-content-center justify-content-lg-between p-4 border-bottom'> <div className='me-5 d-none d-lg-block'> <span>Get connected with us on social networks:</span> </div> <div> <a href='' className='me-4 text-reset'> <MDBIcon fab icon="facebook-f" /> </a> <a href='' className='me-4 text-reset'> <MDBIcon fab icon="twitter" /> </a> <a href='' className='me-4 text-reset'> <MDBIcon fab icon="google" /> </a> <a href='' className='me-4 text-reset'> <MDBIcon fab icon="instagram" /> </a> <a href='' className='me-4 text-reset'> <MDBIcon fab icon="linkedin" /> </a> <a href='' className='me-4 text-reset'> <MDBIcon fab icon="github" /> </a> </div> </section> <section className=''> <MDBContainer className='text-center text-md-start mt-5'> <MDBRow className='mt-3'> <MDBCol md="3" lg="4" xl="3" className='mx-auto mb-4'> <h6 className='text-uppercase fw-bold mb-4'> <MDBIcon icon="gem" className="me-3" /> Company name </h6> <p> Here you can use rows and columns to organize your footer content. Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p> </MDBCol> <MDBCol md="2" lg="2" xl="2" className='mx-auto mb-4'> <h6 className='text-uppercase fw-bold mb-4'>Products</h6> <p> <a href='#!' className='text-reset'> Angular </a> </p> <p> <a href='#!' className='text-reset'> React </a> </p> <p> <a href='#!' className='text-reset'> Vue </a> </p> <p> <a href='#!' className='text-reset'> Laravel </a> </p> </MDBCol> <MDBCol md="3" lg="2" xl="2" className='mx-auto mb-4'> <h6 className='text-uppercase fw-bold mb-4'>Useful links</h6> <p> <a href='#!' className='text-reset'> Pricing </a> </p> <p> <a href='#!' className='text-reset'> Settings </a> </p> <p> <a href='#!' className='text-reset'> Orders </a> </p> <p> <a href='#!' className='text-reset'> Help </a> </p> </MDBCol> <MDBCol md="4" lg="3" xl="3" className='mx-auto mb-md-0 mb-4'> <h6 className='text-uppercase fw-bold mb-4'>Contact</h6> <p> <MDBIcon icon="home" className="me-2" /> New York, NY 10012, US </p> <p> <MDBIcon icon="envelope" className="me-3" /> info@example.com </p> <p> <MDBIcon icon="phone" className="me-3" /> + 01 234 567 88 </p> <p> <MDBIcon icon="print" className="me-3" /> + 01 234 567 89 </p> </MDBCol> </MDBRow> </MDBContainer> </section> <div className='text-center p-4' style={{ backgroundColor: 'rgba(0, 0, 0, 0.05)' }}> © 2021 Copyright: <a className='text-reset fw-bold' href='https://mdbootstrap.com/'> MDBootstrap.com </a> </div> </MDBFooter> ); }
问题截图
- 导航栏与轮播图非全屏状态截图:原本全屏的Navbar和Carousel现在左右出现留白,布局被压缩
- 页脚正常显示截图:页脚组件样式正常,但影响了其他组件的全屏布局
内容的提问来源于stack exchange,提问作者Nico90
相关产品推荐
相关产品推荐

