【发布时间】:2021-06-14 11:55:08
【问题描述】:
这里我有一个侧边栏,我需要高亮选中的标签
我需要在页面更改时突出显示标签...
我怎样才能做到这一点..?
这是我的代码:
react.js:
<Menu>
{SideBarData.map((element, i) => {
return (
<NavIcon onClick={showSidebar} to={element.path} key={i}>
{element.icon}
</NavIcon>
);
})}
</Menu>
style.js
import { Link as LinkS } from "react-router-dom";
const Menu = styled.div`
background: ${BG_COLOR.PRIMARY_COLOR_WHITE};
display: flex;
flex-direction: column;
flex: 1;
width: 56px;
height: 100vh;
margin-left: -8px;
box-shadow: 5px 0 10px -5px #888;
position: fixed;
`;
const NavIcon = styled(LinkS)`
font-size: ${FONT_SIZE.TEXT_NORMAL};
display: flex;
justify-content: flex-start;
justify-content: center;
align-items: center;
height: 3rem;
width: 100%;
color: ${BG_COLOR.PRIMARY_COLOR_BLACK};
text-decoration: none;
border-bottom: 1px solid;
border-bottom-color: ${BG_COLOR.PRIMARY_COLOR_BLACK};
text-align: left;
&:hover {
background-color: ${BG_COLOR.PRIMARY_COLOR};
border-left: 5px solid ${BG_COLOR.PRIMARY_COLOR_BLACK};
cursor: pointer;
}
`;
这里我使用 styled-components 进行样式设置
【问题讨论】:
标签: html css reactjs styled-components