避免在相邻的 HTML 列表之间换行?
简短版本:
当两个列表彼此相邻时,有没有办法使用CSS(或通过其他方式)来防止在两个列表之间添加新行?
长版本(带代码):
我有机器生成的 HTML,它不能智能地处理混合
和
元素的嵌套列表。 (如果您猜到这是 Oracle UCM Dynamic Converter,那么您就获奖了。)具体来说,当源文档嵌套有序列表和无序列表时,生成的 HTML 会将所有有序列表标记关闭回顶层,并开始一个新的列表。无序列表,使用多个无序列表标签来获得所需的缩进级别。
由于这些是块元素,浏览器会在列表之间使用不需要的换行符来呈现它们。如果我可以直接控制 HTML,这会很容易,但可惜。我相信 CSS 是可行的,但我相对有限的 CSS 知识却让我失望。 (天真的使用 style="display: inline;"
与
元素对我来说不起作用。)摘要,我得到:
<ol><li>item 1</li>
<li>item 2</li>
<ol><li>item 1, indent level 2</li>
<li>item 2, indent level 2</li>
</ol></ol>
<ul><ul><ul><li>bullet, indent level3<li>
<li>bullet, indent level3<li>
</ul></ul></ul>
希望,有是一种使其呈现版本如下的方法:
<ol><li>item 1</li>
<li>item 2</li>
<ol><li>item 1, indent level 2</li>
<li>item 2, indent level 2</li>
<ul><li>bullet, indent level3<li>
<li>bullet, indent level3<li>
</ul></ol></ol>
我希望这是一个简单的CSS。
谢谢!
Short version:
When two lists are adjacent to each other, is there a way with CSS (or by some other means) to prevent a new line from being added between the two lists?
Long version (with code):
I have machine-generated HTML that is not intelligently handling nested lists that mix <ol>
and <ul>
elements. (If you guessed that this is Oracle UCM Dynamic Converter, you win the prize.)
Specifically, when the source document nests ordered and unordered lists, the generated HTML closes all the ordered-list tags back to the top level, and begins a new unordered list, using multiple unordered-list tags to get the desired level of indentation.
Since these are block elements, browsers render this with an unwanted newline between the lists. If I had direct control over the HTML, this would be easy, but alas. I believe that CSS is do-able, but my relative thimbleful of CSS knowledge is failing me. (Naive use of style="display: inline;"
with the <ul>
elements didn't work for me.)
Abstracted, I am getting:
<ol><li>item 1</li>
<li>item 2</li>
<ol><li>item 1, indent level 2</li>
<li>item 2, indent level 2</li>
</ol></ol>
<ul><ul><ul><li>bullet, indent level3<li>
<li>bullet, indent level3<li>
</ul></ul></ul>
Hopefully, there is a way to make it the rendered version like this:
<ol><li>item 1</li>
<li>item 2</li>
<ol><li>item 1, indent level 2</li>
<li>item 2, indent level 2</li>
<ul><li>bullet, indent level3<li>
<li>bullet, indent level3<li>
</ul></ol></ol>
I'm hoping this is an easy bit of CSS.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果唯一可见的问题是列表之间的空行,那么简单地:
If the only visible issue is the blank line between the lists, how about simply: