仅在某些儿童组件上应用Bootstrap CSS
我有几个网站A(例如,自定义表格)内置的几个组件。我在Docusaurus中建立了B网站。现在,我想将这些组件复制到网站B上。由于Bootstrap和Docusaurus总体上有冲突。我在想是否可以将引导程序的CSS限制在某些组件上。
例如,最初,我在网站B中的页面myform.mdx.md
中有一个表单:
---
id: 'MyForm'
title: 'MyForm'
sidebar_label: 'MyForm'
---
import MyForm from '../src/components/MyForm';
Page containing MyForm
<MyForm>
</MyForm>
我尝试添加&lt; head&gt;&gt;&gt;&lt; link rel =“ stylesheet” stylesheet“ href =” https://cdn.jsdelivr.net/npm/< /dist/css/bootstrap.min.css“ ... .../&gt;&lt;/head&gt;
to网站a的组件构建src/components/myform/myform/index.jsx.jsx <<网站B的 /代码>:
class MyForm extends React.Component {
constructor(props) {
super(props)
this.state = { successMessage: null }
}
componentDidMount() {}
submit(e) {
this.setState({ successMessage: true })
}
render() {
return (
<>
<Head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous" />
</Head>
<div className="container--fluid container">
<div className="row">
<div className="col">
<form
method="post"
action="https://www.mywebsite.com/download"
onSubmit={this.submit.bind(this)}
>
<div className="row">
<div className="col-lg-6 pt-3">
<div className="form-group">
<input
className="form-control"
placeholder="First name*"
name="firstname"
required
/>
</div>
</div>
<div className="col-lg-6 pt-3">
<div className="form-group">
<input
className="form-control"
placeholder="Last name*"
name="lastname"
required
/>
</div>
</div>
</div>
<div className="row">
<div className="col-lg-12 pt-3">
<div className="form-group">
{this.state.successMessage ? (
<div className="alert alert--success">
Thanks for downloading
</div>
) : (
<button
type="submit"
className="btn btnGreen form-control"
style={{background : "var(--ifm-color-primary-darker)" , border:"1px solid var(--ifm-color-primary-darker)" , color: "#fff"}}
>
Download
</button>
)}
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</>
)
}
}
export default MyForm
网站B的显示显示表格确实具有自举样式。但是,我们可以看到网站B的其他部分(或儿童组件)中的冲突:侧栏,导航等。
因此,有人知道是否只能将Bootstrap的CSS应用于组件myform
?
I have several components of Website A (e.g., a customized form) built in Bootstrap. I have Website B build in Docusaurus. Now, I would like to copy these components to Website B. As Bootstrap and Docusaurus have conflict in general. I'm thinking if it is possible to limit the css of Bootstrap to certain components.
For instance, initially, I have a form in a page myForm.mdx.md
in Website B:
---
id: 'MyForm'
title: 'MyForm'
sidebar_label: 'MyForm'
---
import MyForm from '../src/components/MyForm';
Page containing MyForm
<MyForm>
</MyForm>
I tried to add <Head><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" ... ... /></Head>
to the component of Website A to build src/components/MyForm/index.jsx
of Website B:
class MyForm extends React.Component {
constructor(props) {
super(props)
this.state = { successMessage: null }
}
componentDidMount() {}
submit(e) {
this.setState({ successMessage: true })
}
render() {
return (
<>
<Head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous" />
</Head>
<div className="container--fluid container">
<div className="row">
<div className="col">
<form
method="post"
action="https://www.mywebsite.com/download"
onSubmit={this.submit.bind(this)}
>
<div className="row">
<div className="col-lg-6 pt-3">
<div className="form-group">
<input
className="form-control"
placeholder="First name*"
name="firstname"
required
/>
</div>
</div>
<div className="col-lg-6 pt-3">
<div className="form-group">
<input
className="form-control"
placeholder="Last name*"
name="lastname"
required
/>
</div>
</div>
</div>
<div className="row">
<div className="col-lg-12 pt-3">
<div className="form-group">
{this.state.successMessage ? (
<div className="alert alert--success">
Thanks for downloading
</div>
) : (
<button
type="submit"
className="btn btnGreen form-control"
style={{background : "var(--ifm-color-primary-darker)" , border:"1px solid var(--ifm-color-primary-darker)" , color: "#fff"}}
>
Download
</button>
)}
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</>
)
}
}
export default MyForm
The display of Website B shows that the form does have the Bootstrap style. However, we can see the conflicts in other parts (or children components) of website B: sidebar, navigations, etc.
So does anyone know if it is possible to only apply the css of Bootstrap to the component MyForm
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,您必须覆盖Bootstrap.css后使用的CSS引起的任何“问题”。
No, you'll have to override any "problems" caused by Bootstrap with CSS applied AFTER bootstrap.css.