怎么用:最后一个孩子+:一起来之后?

LBF*_*LBF -1 html css

我不确定为什么这不起作用.我正在尝试更改元素的:after规则:last-child,但它忽略了:last-child:after.

HTML:

<section id="timeline">
    <article></article>
    <article></article>
    <article></article>
</section>
Run Code Online (Sandbox Code Playgroud)

CSS:

#timeline article:after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    height: 100%;
    width: 1px;
    background: #222;
    z-index:1;
}

#timeline article:last-child:after {background:none!important}
Run Code Online (Sandbox Code Playgroud)

演示:https://jsfiddle.net/cd8g2hs0/4/

我已经找到了关于这个问题的其他问题,看起来我正确地做到了.但显然我不是!

bas*_*aus 5

我认为你的代码正在运行 - 它只是没有产生你期望的结果.

尝试将小提琴中CSS的第一行更改为以下内容:

#timeline article {padding:0;position:relative}
Run Code Online (Sandbox Code Playgroud)

这会得到你想要的结果吗?