<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 7 年前。
标签 javascript jquery html css
<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 7 年前。
我将如何选择每一行的第一个元素?
这是我正在尝试做的事情:
黄色圆圈是两个元素连接的地方。我需要使用某种 CSS 选择器在这些之间添加间距。如果需要,我可以使用任何其他语言。
该网站是响应式的,因此我不能只添加“ (分号)”
在中间或者这将使 div 每一行都正确。这与 :not(:first-child) margin-left 的作用相同,因为每行的所有元素都向右移动。
所以,总结一下:
我该怎么做呢?
最佳答案
您可能知道框在哪个屏幕宽度上跳转到下一行,所以只需使用这些断点作为您的 :nth-child()
选择器的提示。
例如:在 >800px 宽的屏幕上,每行显示 4 个 block ?在 @media 屏幕和 (min-width 800px) {
.
所以它看起来像这样:
@media screen and (min-width 800px) {
.classname:nth-child(4n+1) {
margin-right: 2px;
}
}
当然,您将不得不使用 :nth-child()
选择器和断点来准确实现您想要的,但是由于您还没有共享哪怕一小部分代码,我不知道它应该是什么样子。
关于javascript - CSS选择每行的第一个div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31789425/