之前已经回答过,但我发布了一个独立于版本的解决方案。
问题
react-bootstrap
当它与对应的不匹配时开始表现奇怪bootstrap
版本。在 OP 的例子中,警报组件上的关闭按钮的样式不正确。
解决方案
我们需要确保两个库的版本匹配。看看你的内心package.json
文件并查看是什么版本bootstrap
and react-bootstrap
已安装。
包.json:
{
"name": "react-frontend",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:5000",
"dependencies": {
"bootstrap": "5.0.2",
"react-bootstrap": "1.4.3"
// these versions might not match!
}
}
要了解您的版本是否匹配,请访问https://react-bootstrap.github.io https://react-bootstrap.github.io网站并检查右侧下拉的版本:
-
react-bootstrap@2
以上 -bootstrap@5
-
[email protected] /cdn-cgi/l/email-protection
以上 -bootstrap@4
-
[email protected] /cdn-cgi/l/email-protection
以上 -bootstrap@3
要解决给定示例中的问题,请降级到 bootstrap 版本 4:
npm install --save bootstrap@4
or yarn add bootstrap@4
or升级到react-bootstrap 2
npm install --save react-bootstrap@2
or yarn add react-bootstrap@2
就我而言,升级到react-bootstrap不起作用,因为它引入了其他问题,但我成功降级到bootstrap 4。