简体   繁体   English

如何使内联span标记转到下一行而不必将其显示更改为块?

[英]How can I make an inline span tag to go to the next line without having to change its display to block?

How can I make an inline span tag to go to the next line without having to change its display to block? 如何使内联 span标记转到下一行而不必将其显示更改为块?

I want to preserve its inline behaviours because the span tag is meant to contain a short message. 我想保留其内联行为,因为span标记旨在包含一条短消息。 However, because it is inline, its position continues from its previous element (beside its previous element). 但是,因为它是内联的,所以它的位置从前一个元素继续(在前一个元素旁边)。 I need the span to position to the next line, that's, below its previous element rather than side by side. 我需要跨度来定位到下一行,即低于其前一个元素而不是并排。

Is it possible to do this without changing its display to block? 是否可以在不将其显示更改为阻止的情况下执行此操作?

Use this: 用这个:

span:before{
 content: '\a' ; 
 white-space: pre;  
}

The \\a is from: http://www.w3.org/TR/CSS2/syndata.html#strings : \\a来自: http//www.w3.org/TR/CSS2/syndata.html#strings

A string cannot directly contain a newline. 字符串不能直接包含换行符。 To include a newline in a string, use an escape representing the line feed character in ISO-10646 (U+000A), such as "\\A" or "\\00000a". 要在字符串中包含换行符,请使用表示ISO-10646(U + 000A)中换行符的转义符,例如“\\ A”或“\\ 00000a”。 This character represents the generic notion of "newline" in CSS. 此字符表示CSS中“newline”的一般概念。

You could throw the span into a block element, like a paragraph element. 您可以将span转换为块元素,就像段落元素一样。 Or you could place an invisible horizontal rule between the span and the elements you want to be on the previous line. 或者,您可以在跨度和要在前一行上的元素之间放置一条不可见的水平线。 Or you could throw in a line break element. 或者你可以抛出换行元素。

暂无
暂无

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

相关问题 如何使跨度 go 到下一行 - How to make span go to the next line 带显示的跨度标记:内联呈现为display:block - Span tag with display:inline rendering as display:block 使用jQuery,我如何将鼠标悬停在一个元素上并使其其余兄弟姐妹更改大小? 没有DIV下降到下一行? - Using jQuery how can i on hover make an element active and make the rest of its siblings change sizes? without DIV dropping to the next line? 如何使内嵌标签<a>在块标签后</a>内联<a>显示</a> <p> <a>?</a> - How to make an inline tag <a> display inline after a block tag <p>? HTML-如何插入 <span></span> 标记到每行 <pre></pre> 块没有硬编码? - HTML - How do I insert a <span></span> tag into each line of a <pre></pre> block without hard coding? 如何使内联块元素跨越文本行的其余部分? - How to make an inline-block element span the rest of the text line? 如何使容器div仅水平溢出而不使用“display:inline-block”作为其内部div? - How do I make a container div only overflow horizontally without using “display:inline-block” for its inner divs? 如何在不使用span标签的情况下使短文本中的前几个单词以斜体和小写字母显示? - How can I make the first few words in a short block of text appear in italics and small caps without using a span tag? 如何使用css使span元素转到下一行 - how to make the span element go to the next line using css 跨度标记上的 CSS 变换元素(连同显示:内联块)正在强制换行 - CSS Transform element on span tag (along with display: inline-block) is forcing a line break
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM