要解决上述问题,需要稍微修改一下策略。而不是有一个
ActiveTabBorder
组件的引用并根据元素的位置呈现结果,我们在
TabTitleItem
用一个
:after
伪元素,并使用
display: flex
您的样式化组件如下所示
export const ListTabs = styled.ul`
padding-left: 0;
list-style: none;
margin: 0;
display: flex;
justify-content: center;
`;
export const TabTitleItem = styled.li`
position: relative;
transition: all 800ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
padding: 16px 30px;
cursor: pointer;
opacity: 0.4;
display: flex;
flex-direction: column;
align-items: center;
${props =>
props.isActiveTab &&
`
transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
cursor: default;
opacity: 1;
&:after {
content: '';
height: 5px;
background-color: blue;
position: absolute;
bottom: 0;
transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
width: 100%;
}
`}
`;
Working demo