简体   繁体   English

防止跨度元素包裹

[英]Prevent span elements from wrapping

My UI shows a list of email addresses retrieved by backbone. 我的用户界面显示了骨干网检索的电子邮件地址列表。 It is currently rendered as a span of span s that contain span s. 当前将其渲染为包含spanspanspan Here's some typical generated html: 这是一些典型的生成的html:

在此处输入图片说明

But I am getting breaks inside the span s (notice the beginning of angelstwo is on two lines), probably because I am using the wrong html tags ( ul and li sounds better for a list). 但是我在span s内遇到了中断(注意angelstwo的开头在两行上),可能是因为我使用了错误的html标记( ulli对于列表听起来更好)。 It can look like this: 它看起来可能像这样:

在此处输入图片说明

I tried div s but I got one entry per line and I don't want that. 我尝试了div但是每行只有一个条目,但我不想要这样。

Is there something I can do to make this work with span s? 我可以做些什么来使span s起作用吗? Or should I change to something else like ul and li ? 还是我应该换成ulli类的东西?

span elements are, by default, inline elements. 默认情况下, span元素是内联元素。 In an inline formatting context boxes can wrap. 嵌入式格式中,上下文框可以包装。 (This is what happens to text when it wraps around a floated image.) (这就是文本环绕浮动图像时发生的情况。)

div elements are, by default, block elements. div元素默认情况下是块元素。 In a block formatting context the boxes will occupy all available horizontal space ( width: 100% ). 块格式化上下文中,这些框将占据所有可用的水平空间( width: 100% )。

This is why your spans and divs aren't working as you want. 这就是为什么您的跨度和div无法按需工作的原因。

If you switch from display: inline to display: inline-block , you'll get block-level like behavior, which will prevent wrapping line boxes, but elements will stack horizontally with other inline elements. 如果从display: inline切换到display: inline-block ,将获得类似于块级的行为,这将防止换行,但元素将与其他内联元素水平堆叠。

W3C References: W3C参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM