admin管理员组文章数量:1336367
I have a styled ponent which looks like:
import styled from 'styled-ponents';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
export const CategoryList = styled(List)`
`;
//this is what i want to change
export const CategoryListItem = styled(ListItem)`
border-top: 2px solid #f4f4f4;
`;
export const CategoryListItemText = styled(ListItemText)`
padding-left: 5px;
`;
export const ListItemHeading = styled(ListItem)`
background-color: #f4f4f4;
`;
How can I use siblings in this case & + & ?
I want to achieve something like :
li + li {
border-top: 1px solid red;
}
How can I achieve this?
I have a styled ponent which looks like:
import styled from 'styled-ponents';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
export const CategoryList = styled(List)`
`;
//this is what i want to change
export const CategoryListItem = styled(ListItem)`
border-top: 2px solid #f4f4f4;
`;
export const CategoryListItemText = styled(ListItemText)`
padding-left: 5px;
`;
export const ListItemHeading = styled(ListItem)`
background-color: #f4f4f4;
`;
How can I use siblings in this case & + & ?
I want to achieve something like :
li + li {
border-top: 1px solid red;
}
How can I achieve this?
Share Improve this question edited Jan 15, 2020 at 18:41 Brett DeWoody 62.9k31 gold badges144 silver badges192 bronze badges asked Jan 15, 2020 at 18:30 AckmanAckman 1,5926 gold badges32 silver badges57 bronze badges1 Answer
Reset to default 6This is done the same way as in SCSS with &
:
export const CategoryListItem = styled(ListItem)`
border-top: 2px solid #f4f4f4;
& + & { // this will work for <CategoryListItem /><CategoryListItem />
border-top: 1px solid red;
}
`;
You can also style with html elements but the code above is a better practice
& + li { // this will work for <CategoryListItem /><li />
border-top: 1px solid red;
}
Basically you can do any nesting with &
& li { // this will work for <CategoryListItem><li /></CategoryListItem>
}
& li.test { // this will work for <CategoryListItem><li class="test" /></CategoryListItem>
}
You can read it up in the official docs: https://styled-ponents./docs/basics#pseudoelements-pseudoselectors-and-nesting
本文标签: javascripthow to use sibling selector css in styledStack Overflow
版权声明:本文标题:javascript - how to use sibling selector css in styled - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742405181a2468674.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论