如何在 React-Bootstrap 组件中将填充/边距作为props传递
IT技术
reactjs
twitter-bootstrap-3
bootstrap-4
react-bootstrap
2021-05-20 22:28:02
4个回答
首先在您的src/index.js
或App.js
import 'bootstrap/dist/css/bootstrap.min.css';
然后你可以通过className
在 React 中传递所需的引导 CSS 类名作为prop来设置你的组件的样式,例如:
import React from "react"
import Container from "react-bootstrap/Container";
function MyComponent() {
return (
<Container fluid className="p-0">
<SomeOtherComponent />
</Container>
);
}
export default MyComponent
上面的代码会将p-0
CSS 类添加到Container
.
参考
您可以使用默认的 React 样式添加边距和填充:
const divStyle = {
marginLeft: '10px',
};
function HelloWorldComponent() {
return <div style={divStyle}>Hello World!</div>;
}
从这里引用
答案是:React Bootstrap 没有使用边距/填充的props。
您可以将props用于 col 类,但不能用于边距。
例子:
<Col className="col-6 col-md-3 mb-3 pt-2">
// there you have a Col component from React-Bootstrap 4
// it has some grid system classes, that you can use as props like this:
https://react-bootstrap.github.io/layout/grid/
<Col xs={6} md={3} className="mb-3 pt-2">
// but as you can see, the native classes of Bootstrap 4 like
// mt, mb, pt, pb etc, they have not a props use with
// React-Bootstrap, you have to use them like regular classes
// inside "className"
您需要将 className="p-5" 添加到元素中。这在 react-bootstrap 中没有记录,但在原始 Bootstrap 4 文档中:https : //getbootstrap.com/docs/4.4/utilities/spacing/#examples
其它你可能感兴趣的问题