首页 > 解决方案 > css 选择器 - 选择第一个和最后一个之间的每个 div

问题描述

如何在容器中的第一个和最后一个 div 之后选择 div 元素,以便选择介于两者之间的所有内容

我的css中有这个

&--marker {
        background: green;
        width: 20px;
        height: 20px;
        border-radius: 100%;
        position: absolute;
        top: 50%;
        transform: translate3d(0, -50%, 0);

        &:first-child {
            left: calc((100% / var(--index)));
        }

        // selector below doesn't work
        &:nth-of-type():not(:first-of-type):not(:last-of-type) {                
            left: calc((100% / (var(--index) + 1)) - (var(--width)/2));
        }

        &:last-child {
            left: calc((100%  - var(--width));

        }
    }

标签: javascripthtmljquerycss

解决方案


你可以试试这个:

.container div:not(:first-child):not(:last-child) {
       /* css here */
}

推荐阅读