html - 如何使用:last-child + :after together?

标签 html css

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

HTML:

<section id="timeline">
    <article></article>
    <article></article>
    <article></article>
</section>

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}

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

我发现了有关此问题的其他问题,看来我做对了。但显然我不是!

最佳答案

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

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

#timeline article {padding:0;position:relative}

这是否得到了您想要的结果?

关于html - 如何使用:last-child + :after together?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33046540/

相关文章:

html - CSS 类未正确应用于网站上的图像

javascript - 谷歌标记的网站中的恶意软件

html - CSS Position 图片比容器大

javascript - 面临给用户提供取消静音自动播放Vimeo iframe嵌入的选项的麻烦

css - 如何使用 CSS 从自定义菜单中删除点

html - SVG/CSS : Masked Header Logo

HTML/CSS - &lt;input&gt; 宽度

javascript - 使用边框的带有右圆 Angular 箭头 css 的部分划分

javascript - 如何在谷歌地图上制作 div 区域

javascript - JSFiddle 下拉按钮不可点击