如何在jss中select first or last child
How to select first or last child in jss
我在我的 React 项目中使用 JSS(Javascript Style Sheets)
。我试图 select first-child
或 last-child
,所以我尝试了以下
carousel: {
"& img:first-child": {
padding: "0 5px"
}
},
然而,它不起作用。在 Chrome 开发者工具中,它正确显示正确的 CSS 代码,但是由于某些原因,它 select 每个 img 标签,而不仅仅是 first-child。我如何才能 select JSS 中的第一个元素?
JSS 只是一个编译器,一旦它产生了有效的 CSS 并且你验证了它的正确性,你必须在其他地方搜索错误。我觉得你的选择器没问题。
但是如果您只关心容器中的第一个child而不是child的类型,那么您可以只使用
carousel: {
"& > :first-child": {
padding: "0 5px"
}
},
- 一般情况下,一个容器内的所有child都属于同一类型,所以child的类型每次都无关紧要。
我在我的 React 项目中使用 JSS(Javascript Style Sheets)
。我试图 select first-child
或 last-child
,所以我尝试了以下
carousel: {
"& img:first-child": {
padding: "0 5px"
}
},
然而,它不起作用。在 Chrome 开发者工具中,它正确显示正确的 CSS 代码,但是由于某些原因,它 select 每个 img 标签,而不仅仅是 first-child。我如何才能 select JSS 中的第一个元素?
JSS 只是一个编译器,一旦它产生了有效的 CSS 并且你验证了它的正确性,你必须在其他地方搜索错误。我觉得你的选择器没问题。
但是如果您只关心容器中的第一个child而不是child的类型,那么您可以只使用
carousel: {
"& > :first-child": {
padding: "0 5px"
}
},
- 一般情况下,一个容器内的所有child都属于同一类型,所以child的类型每次都无关紧要。