React Bootstrap选项卡自定义类无效

发布于 2025-01-23 21:57:12 字数 1014 浏览 0 评论 0 原文

我使用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 的父类,但是如果没有父母类,则可以使用。但是我需要一个父级才能单独设计。

I use react bootstrap tabs component but when i use a custom css within this nav-link with a custom parent class indicator its not working.

<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>

Here is my css parent indicator:

.approval-details-tab > .nav-tabs .nav-link.active::before {
  content: "";
  background: #524eb7;
  width: 30px;
  height: 3px;
  position: absolute;
  top: 63% !important;
}

I use .approval-details-tab class as a parent class of nav-tabs but without parent class it works. but i need a parent class for separate design.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻梦旅人 2025-01-30 21:57:12

来自 react-bootstrap文档::

由于React-Bootstrap不取决于Bootstrap的非常精确的版本,因此我们不使用任何随附的CSS发货。但是,使用这些组件需要一些样式表。

您包含的方式和哪些引导样式取决于您,但最简单的方法是包括CDN中的最新样式。

cdn链接:

​像这样的内部标签:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"/>

现在,要覆盖任何类别的“ react-bootstrap”类,您必须在自定义CSS上使用“!如果您想覆盖背景颜色,请在CSS属性旁边使用“!重要”。

示例:

.approval-details-tab{
   background: #524eb7 !important;
}

为了更清楚地了解您的问题,请提及您想覆盖Bootstrap类的CSS-Property。谢谢!

From the React-bootstrap documentation:

Because React-Bootstrap doesn't depend on a very precise version of Bootstrap, we don't ship with any included CSS. However, some stylesheet is required to use these components.

How and which Bootstrap styles you include is up to you, but the simplest way is to include the latest styles from the CDN.

CDN link: https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css

Add CDN at index.html file inside tag like this:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"/>

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:

.approval-details-tab{
   background: #524eb7 !important;
}

To get more clear understanding of your problem, please mention which css-property you want to override of a bootstrap class. Thanks!

忆离笙 2025-01-30 21:57:12

在React中,亲子关系有些复杂。尽管React中的一个组件似乎是另一个组件的直接孩子,但是将其转换为正常HTML,但事实并非如此。例如,查看此代码

<div className="parent">
    <Tabs className="children"> 
       some other components inside
    </Tabs>
</div>

div 组件的直接父 tabs ?它不是。上面的代码被翻译成正常的HTML时,就像

<div className="parent">
   <div>
     <div className="children">
       some other components inside
     </div>
   </div>
</div>

您看到的那样大致看起来像这样,带有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

<div className="parent">
    <Tabs className="children"> 
       some other components inside
    </Tabs>
</div>

Does div the direct parent of the component Tabs? It is not. The above code, when being translated to normal HTML component would look roughly like this

<div className="parent">
   <div>
     <div className="children">
       some other components inside
     </div>
   </div>
</div>

As 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文