Html 如何在两个div之间插入pseudo?
在向div元素插入伪元素时,遇到了一个棘手的情况。这是我的html结构Html 如何在两个div之间插入pseudo?,html,css,pseudo-element,Html,Css,Pseudo Element,在向div元素插入伪元素时,遇到了一个棘手的情况。这是我的html结构 <div class="collections-list"> <div class="collection">...</div> <div class="collection">...</div> <div class="collection">...</div> (where I want to put the pseudo
<div class="collections-list">
<div class="collection">...</div>
<div class="collection">...</div>
<div class="collection">...</div>
(where I want to put the pseudo element)
<div class="collection">...</div>
...
</div>
但这会将伪元素插入div.collection
。我不想创建一个元素并在div之间添加它,因为我确实想更改DOM并用它绑定许多js函数
使用css可以做到这一点吗?这里有一个使用和order
属性的解决方案
与其他答案不同,这通过将伪元素插入.collections list
元素之间的.collection
元素来回答您的问题,而不是将伪元素插入.collection
div
。收藏列表{
显示器:flex;
弯曲方向:立柱;
}
.collections列表::之后{
内容:“伪”;
顺序:1;
}
.集合:第n个子项(n+4){
顺序:2;/*第四个及以后。集合元素的顺序更高*/
}
1.
2.
3.
4.
5.
什么是解除我的和DIPPAans@SanjuPrajapati我的答案中的伪元素是.collections list
的子元素,而不是.collection
元素之一的子元素。OP在问题中特别提出了这个问题。这就是我需要的,谢谢。Flexbox是一个绝妙的想法。
div.methods-collections-lander div.collection:nth-child(3n)::after