我正在尝试自定义 react-bootstrap 导航栏的颜色。
这是我的 NavbarComponent.cs 文件的内容:
var React = require('react');
var ReactDOM = require('react-dom');
import Navbar from 'react-bootstrap/lib/Navbar';
import Nav from 'react-bootstrap/lib/Nav';
import NavItem from 'react-bootstrap/lib/NavItem';
import Button from 'react-bootstrap/lib/Button';
import styles from './Navbar.css'
export default class NavigationBar extends React.Component {
render() {
return (
<Navbar brand="react-bootstrap" className={styles.navbar}>
<Nav bsStyle="tabs" activeKey="1" onSelect= {this.handleSelect}>
<NavItem className={styles.navitem} eventKey={1} href="#">Thing 1</NavItem>
<NavItem className={styles.navitem} eventKey={2} href="#">Thing 2</NavItem>
</Nav>
</Navbar>
);
}
}
这是我的 CSS 覆盖文件,Navbar.css:
:local(.navbar) {
background:#2E5F91;
color:white !important;
}
:local(.navitem) {
color:white !important;
}
导航栏的背景颜色可以很好地改变,但是我无法改变文本颜色,即使使用!important
标签(这很危险,我知道)。
查看结果页面中的元素:
<li role="presentation" class="BV2R0XKa1lLedUhy9CO2p" data-reactid=".1.1.0.0.$/=10">
<a href="#" role="button" data-reactid=".1.1.0.0.$/=10.0">Thing 1</a>
</li>
看起来我的类不够深入。我该如何解决这个问题?
:local
和:global
是新的伪类,用于表示CSS选择器的作用域。这是将关注点分离为模块的一种非常好的方式,这里有一篇关于这个主题的优秀文章https://medium.com/seek-developers/the-end-of-global-css-90d2a4a06284#.oehp2f673 - deiga