css - 在 react-bootstrap 中更改 NavDropdown 的颜色和背景颜色

标签 css reactjs twitter-bootstrap-3 react-bootstrap

和我的NavDropdownreact-bootstrap ,我无法设置其颜色或背景颜色的样式...

<NavDropdown eventKey={3} className="text-center" style={{ fontSize: `130%` }} title="Items to Choose" >
  <LinkContainer to="/about">
    <MenuItem eventKey={3.1} className="text-center">About</MenuItem>    
  </LinkContainer>
  <MenuItem divider />
  <LinkContainer to="/products">
    <MenuItem eventKey={3.2} className="text-center">Products</MenuItem>    
  </LinkContainer>      
  <MenuItem divider />
  <LinkContainer to="/blog-index">
    <MenuItem eventKey={3.3} className="text-center">Blog</MenuItem>    
  </LinkContainer>
</NavDropdown>

我可以使用 style={{ fontSize: '130%' }} 更改字体大小,但我还想使用 .. 更改颜色和背景颜色。

style={{ fontSize: '130%', color: '#fff', backgroundColor: 'blue' }}

...但是 colorbackgroundColor不要在括号内工作。

我尝试做的一件事是包装 <NavDropdown>样式中的元素 div ,但这搞乱了 Navbar 元素的对齐方式。

最佳答案

也可以将标题文本作为 JSX 元素提供。

<NavDropdown
    title={
        <span className="text-primary my-auto">Dropdown</span>
    }
    id="nav-dropdown"
>
    <NavDropdown.Item>Action</NavDropdown.Item>
    <NavDropdown.Item>Another action</NavDropdown.Item>
</NavDropdown>

而且不需要编写自定义 CSS,这可能是我们希望避免的事情。

关于css - 在 react-bootstrap 中更改 NavDropdown 的颜色和背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50970773/

相关文章:

html - 图像在 div 中不正确

javascript - 无法获取 SVG 矩形计算样式

css - 不同 :focus styles possible depending on if user clicks an element or tabs to it?

javascript - 一段时间后无法点击注册下拉菜单

javascript - 如何防止模态点击?

html - 将水平制表符从 Bootstrap 3 转换为 Bootstrap 4

javascript - 工作灯负载指示器

javascript - React js 简单获取 json 并列出内容 "TypeError: this.state.items.map is not a function"

reactjs - 如何使变量的类型为未知或 'Movie' 分配?

html - 小型设备中的 Bootstrap 下拉菜单