【发布时间】:2019-02-01 07:37:06
【问题描述】:
在知道a list-item element cannot be display: flex at the same time之后,我用一个容器包装了我的内容,然后将容器放入<li />中。
对于有内容的元素来说一切都是正确的。
但是,如果容器中的第一个元素没有子节点,则<li /> 的标记意外地位于底部。
虽然就我而言,我可以简单地添加一个display: none 来解决问题,但我仍然感到困惑:
flexbox 中的内容如何影响其祖父节点?
示例:(标记1.位于<li />的右下角)
.flex { display: flex; }
<ol style="width: 15em">
<li>
<div class="flex">
<div></div>
<div>When an element without content is preceding, the ::marker of the list-item is located at the bottom.</div>
</div>
</li>
<li>
<div class="flex">
<div>TITLE</div>
<div>If there's content in the first element, then it goes as expected.</div>
</div>
</li>
<li>
<div class="flex">
<div>It's also fine if there's only one child here.</div>
</div>
</li>
</ol>
相关问题:
CSS伪元素::marker在流行的浏览器中没有实现,只有Firefox支持@counter-style。现在建议在<ol /> 中实现用户定义的标记? (我看到有人使用::before 这样做,以使用户不要复制标记的文本。但我不知道它是否好。)
【问题讨论】:
-
如果您删除原生 HTML 列表样式
list-style: none并使用伪元素和 css 计数器添加您自己的样式,您将获得更多控制 -
使用 ::before 是一种可怕的 hack,它带有各种各样的陷阱,试图假装某物是一个标记,而实际上它不是,但这是我们多年来所拥有的一切,并将继续只要 ::marker 仍未实现,就一直坚持下去。换句话说,“它和它会得到的一样好”。