Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 views
in Technique[技术] by (71.8m points)

html - Flexbox inside list item doesn't align to the top of the list item

Putting a flexbox inside of a list item is causing the content to get pushed down by what appears to be a full line height.

I've been playing around with different CSS properties, such as giving the flexbox margin-top: 0, its children margin-top:0, adding flex-wrap to the flexbox, etc. No dice!

.wrapper {
  display: flex;
}
li {
  background: #ccc;
}
<ul>
  <li>
    <div class="wrapper">
      <div>hello</div>
      <div>world</div>
    </div>
  </li>
</ul>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This seems due to the ::marker pseudo-element.

I don't know exactly what should happen because this is an overlap of various specs

And it's problematic because they are proposals not ready for implementation. See for example the warning in CSS Lists 3 - Positioning Markers, which is also relevant in this issue:

This section is not ready for implementation. It is an unreviewed rough draft that hasn’t even been properly checked for Web-compatibility. Feel free to send feedback, but DON’T USE THIS PART OF THE SPEC.

The following is my guess of how Chrome handles markers under the hood.

First, let's use the simpler list-style-position: inside on the list item, and let it contain a block:

ul {
  list-style-position: inside;
}
li {
  border: 1px solid blue;
}
div {
  border: 1px solid red;
}
<ul>
  <li>
    <div>Hello<br />world</div>
  </li>
</ul>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...