【发布时间】:2021-10-26 16:38:00
【问题描述】:
我有一个导航列表,想在导航项前面放置一个图标,所以我这样做了,但它会将相同的图标放在所有导航项上。
如何选择 1、2、3 和 4 导航项并在 CSS 中为每个导航项放置不同的导航图标?
它不工作,仍然显示第一个图标,没有改变 2,3 和 4。???? ????
.shop-menu .mobile-nav__link:nth-child(1)::before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 2em;
height:100%;
background: url("/files/NewArrivalsIcon.png?v=1635225557") no-repeat center center transparent;
background-size: contain;
}
.shop-menu .mobile-nav__link:nth-child(2)::before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 2em;
height:100%;
background: url("files/AnimalPrintsIcon.png?v=1635225557") no-repeat center center transparent;
background-size: contain;
}
.shop-menu .mobile-nav__link:nth-child(3)::before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 2em;
height:100%;
background: url("files/Under500Icon.png?v=1635225557") no-repeat center center transparent;
background-size: contain;
}
.shop-menu .mobile-nav__link:nth-child(4)::before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 2em;
height:100%;
background: url("files/NewArrivalsIcon.png?v=1635225557") no-repeat center center transparent;
background-size: contain;
}
【问题讨论】:
-
没有看到您的 HTML 结构,我们只能猜测。请把它放在你的问题中。值得我猜的是,您的物品都是他们各自父母的第一个孩子,所以您每次都得到第一个 img。
标签: css css-selectors html-lists