React Bootstrap选项卡自定义类无效
我使用React Bootstrap TABS
组件,但是当我在此 nav> nav-link
中使用自定义的父母类指示器时,它无法正常工作。
<Tabs
defaultActiveKey="signup_renter"
id="uncontrolled-tab-example"
className="mb-3 approval-details-tab"
>
<Tab eventKey="signup_renter" title="About Car">
<div className="signup-renter">
this is signup renter tab
</div>
</Tab>
<Tab eventKey="signup_host" title="Details">
<div className="signup-host">
this is signup host tab
</div>
</Tab>
</Tabs>
这是我的CSS父级指标:
.approval-details-tab > .nav-tabs .nav-link.active::before {
content: "";
background: #524eb7;
width: 30px;
height: 3px;
position: absolute;
top: 63% !important;
}
我使用 .approval-details-tab
类作为 nav> nav-tabs
的父类,但是如果没有父母类,则可以使用。但是我需要一个父级才能单独设计。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 react-bootstrap文档::
像这样的内部标签:
现在,要覆盖任何类别的“ react-bootstrap”类,您必须在自定义CSS上使用“!如果您想覆盖背景颜色,请在CSS属性旁边使用“!重要”。
示例:
为了更清楚地了解您的问题,请提及您想覆盖Bootstrap类的CSS-Property。谢谢!
From the React-bootstrap documentation:
Add CDN at index.html file inside tag like this:
Now, to override any class of `react-bootstrap', you have to use "!important" on your custom css. If you want to override the background color, use "!important" beside that css property.
Example:
To get more clear understanding of your problem, please mention which css-property you want to override of a bootstrap class. Thanks!
在React中,亲子关系有些复杂。尽管React中的一个组件似乎是另一个组件的直接孩子,但是将其转换为正常HTML,但事实并非如此。例如,查看此代码
div
组件的直接父tabs
?它不是。上面的代码被翻译成正常的HTML时,就像您看到的那样大致看起来像这样,带有className
儿童
的元素不再是父件的直接子。这就是为什么在React中,使用父级儿童关系为组件进行样式组件并不是一个好主意。如果您只想因为想避免命名冲突而进行这种样式,则可以尝试 css模块
如果要读取有关
tabs
组件行为的详细信息,则可以读取源代码In React, the parent-children relationship is a bit complicated. Although a component in React seemed to be the direct child of another component, when translated to normal HTML, it doesn't. For example, take a look at this code
Does
div
the direct parent of the componentTabs
? It is not. The above code, when being translated to normal HTML component would look roughly like thisAs you can see, the element that bears the className
children
is no longer the direct child of the parent component. That is why in React, it is not a good idea to style components using parent-direct children relationship.If you just want to do this way of styling because you want to avoid naming conflict, you can try out CSS Module
If you want to read the detail on how the
Tabs
component behave, you can read the source code