:last-child:before with column-count behaving diff

2019-09-07 11:42发布

The expected behaviour (Firefox)

The expected behaviour

The unexpected (Chrome)

The wrong behaviour

The JSFiddle demo

http://jsfiddle.net/bZaKK/ (try it in Firefox and Chrome to see the difference).

The HTML

<ul>
  <li><a href="">List item 1</a></li>
  <li><a href="">List item 2</a></li>
  ...
  <li><a href="">List item 9</a></li>
</ul>

The CSS

ul {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  -moz-column-count: 4;
  -webkit-column-count: 4;
  column-count: 4;
  }

li:last-child:before {
  position: absolute;
  content: " ";
  display: block;
  background-color: red;
  height: 1px;
  top: -1px;
  width: 100%;
  }

The question

Why is this happening and how can I fix it with pure CSS? Is it a firefox bug or chrome bug?

Note: I found this apparent bug while answering this question: Styling the first item in a css column.

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-09-07 12:28

Chrome is actually giving the proper behaviour. The unordered list is given position:relative, so the line will be positioned absolute, relative to ul.

Adding left:0 to li:last-child:before will give the same behaviour in firefox

http://jsfiddle.net/bZaKK/2/

查看更多
登录 后发表回答