【发布时间】:2020-12-02 01:50:52
【问题描述】:
我有一个浮动图像,后跟一个无序列表。默认情况下,这会导致列表项目符号与图像重叠。
img {
float: left;
}
<img src="https://picsum.photos/200/100" />
<ul>
<li>A list element.</li>
<li>An element with some text that might be long enough to wrap to the next line. That sentence won't do it, but maybe if I add another I can demonstrate this issue.</li>
<li>Another simple element</li>
<li>Number 4</li>
<li>A fifth</li>
<li>Now this one should be below the image.</li>
</ul>
正如this question 所指出的,overflow: hidden 解决了重叠问题,但一旦到达图像底部,就会导致列表元素不再左对齐。
list-style-position: inside 将项目符号移到图像之外,但使项目中的文本不再一致地对齐(即第一行被项目符号偏移,其余的与项目符号而不是第一行对齐)。
img {
float: left;
}
ul {
list-style-position: inside;
}
<img src="https://picsum.photos/200/100" />
<ul>
<li>A list element.</li>
<li>An element with some text that might be long enough to wrap to the next line. That sentence won't do it, but maybe if I add another I can demonstrate this issue.</li>
<li>Another simple element</li>
<li>Number 4</li>
<li>A fifth</li>
<li>Now this one should be below the image.</li>
</ul>
是否有可能以一种简单的方式做到这一点?
编辑:我还想以允许浮动元素旁边的非列表文本正常运行的方式进行设置,因此仅添加边距也不起作用
【问题讨论】:
标签: css alignment css-float html-lists