Reactjs 如何用样式化组件覆盖.styl文件中的属性?
我正在尝试自定义,以适应我的网页的配色方案。可以通过使用样式化组件修改sidenav组件的样式来定制侧边栏 我试图覆盖以下.styl中元素的颜色Reactjs 如何用样式化组件覆盖.styl文件中的属性?,reactjs,styled-components,stylus,Reactjs,Styled Components,Stylus,我正在尝试自定义,以适应我的网页的配色方案。可以通过使用样式化组件修改sidenav组件的样式来定制侧边栏 我试图覆盖以下.styl中元素的颜色 .sidenav-nav > .sidenav-navitem { clear: both; position: relative; &.highlighted > .navitem { cursor: default; } &:hover > .navite
.sidenav-nav > .sidenav-navitem {
clear: both;
position: relative;
&.highlighted > .navitem {
cursor: default;
}
&:hover > .navitem::after {
background: #fff;
opacity: .15;
}
&.highlighted > .navitem::after,
&:hover.highlighted > .navitem::after {
background: #000;
opacity: .2;
}
&.highlighted.expanded > .navitem::after,
&:hover.highlighted.expanded > .navitem::after {
background: #000;
opacity: .25;
}
&.highlighted.selected.expanded > .navitem::after,
&:hover.highlighted.selected.expanded > .navitem::after {
background: #000;
opacity: .2;
}
&:hover > .navitem .navicon,
&.highlighted > .navitem .navicon {
opacity: 1;
}
&:hover > .navitem .navicon,
&:hover > .navitem .navtext,
&.highlighted > .navitem .navicon,
&.highlighted > .navitem .navtext {
color: #fff;
> * {
color: #fff;
}
}
> .navitem {
position: relative;
display: block;
line-height: 50px;
height: 50px;
white-space: nowrap;
text-decoration: none;
color: #fff;
font-size: 14px;
cursor: pointer;
&:focus {
outline: 0;
}
// Background layer
&::after {
content: '';
position: absolute;
width: 100%;
top: 0;
bottom: 0;
left: 0;
background: #fff;
opacity: 0;
z-index: -1;
}
}
> .navitem .navicon,
> .navitem .navtext {
color: #f9dcdd;
> * {
color: #f9dcdd;
}
}
> .navitem .navicon {
display: block;
float: left;
width: 64px;
height: 50px;
margin-right: -6px;
vertical-align: top;
background-repeat: no-repeat;
background-position: center center;
background-color: transparent;
opacity: .7;
line-height: 50px;
text-align: center;
}
> .navitem .navicon + .navtext {
width: 0;
visibility: hidden;
opacity: 0;
transition: visibility 0s .2s, opacity .2s linear;
}
}
具体而言,本部分:
> .navitem .navicon,
> .navitem .navtext {
color: #f9dcdd;
> * {
color: #f9dcdd;
}
}
此文件由NavItem组件使用。
在一个单独的文档中,我从react sidenav包导入NavItem,并添加其他样式,如下所示。此代码在react sidenav repo的导航栏样式示例中提供:
const StyledNavItem = styled(NavItem)`
&&&:hover {
[class*="navtext--"] {
color: #222;
}
}
}
`;
如何使用不同的颜色定位和覆盖颜色代码#f9dcdd
编辑1
我试过了,但没有成功:
const StyledNavItem = styled(NavItem)`
&&&:hover {
[class*="navtext--"] {
color: #222;
}
}
&&&> .navitem .navicon,
> .navitem .navtext {
color: #fff;
> * {
color: #fff;
}
}
}
`;
如果使用不同的颜色代码重新复制规则,会发生什么情况:
.navitem.navtext{color:red;}
。同时确保它具有更高的特异性。谢谢您的回复。我试过了,但没用。请看我的编辑1