css - 样式来自 css 的 react-bootstrap 按钮
问题描述
总的来说,我对 React 和 JavaScript 还很陌生。
我正在使用来自https://react-bootstrap.github.io/components/buttons/的 react-bootstrap的 Button 但我想在我的 css 文件中的 React 应用程序中设置 Button 的样式,但它似乎没有申请。
我的 Home.js 文件看起来像
import React from "react";
import '../App.css'; // Reflects the directory structure
export default function Home() {
return (
<div>
<h2>Home</h2>
<Button variant="light" className="formButtons">
</div>
)
}
我的 App.css 文件看起来像
.formButtons {
margin: 10;
overflow-wrap: break-word;
color: red;
}
我可以说它不适用,因为文本颜色不是红色。
提前致谢!
解决方案
首先,您需要从react-bootstrap导入 Button 元素。你可以这样写:
import Button from 'react-bootstrap/Button'
之后,您可以删除 className 属性,因为 React Bootstrap 以您可以依赖的一致方式构建组件 classNames。您可以将样式基于变体属性,因此请尝试以下操作:
主页.js
import React from "react";
import Button from 'react-bootstrap/Button'
import '../App.css'; // Reflects the directory structure
export default function Home() {
return (
<div>
<h2>Home</h2>
<Button variant="light">TEXT</Button>
</div>
)
}
应用程序.css
.btn-light {
margin: 10;
overflow-wrap: break-word;
color: red;
}
推荐阅读
- python - Opening Firefox with selenium error
- php - php jquery mysql - 在循环中的另一个加载更多中加载更多按钮
- d3.js - D3 力导向图(v4)不接受 img 作为节点
- java - 返回 ArrayList 大小不起作用
- ruby-on-rails - Why does strong params order in Rails matter?
- ios - AirPlay 接收器文档
- r - 使用 RWeka 时尝试将 Rmd 文件编织到 Word 的问题
- scalability - Design of HA, consistent and responsive counter
- python - python - 比较两个csv文件并生成报告
- javascript - 如何在android应用程序的webview中动态更改应用于网页的样式(css)