Prevent line-break of span element

前端 未结 4 1618
一个人的身影
一个人的身影 2020-12-07 10:51

I have a element which I want to display without any line break. How can I do that?

4条回答
  •  情书的邮戳
    2020-12-07 11:22

    white-space: nowrap is the correct solution but it will prevent any break in a line. If you only want to prevent line breaks between two elements it gets a bit more complicated:

    Some text

    To prevent breaks between the spans but to allow breaks between "Some" and "text" can be done by:

    p {
        white-space: nowrap;
    }
    
    .text {
        white-space: normal;
    }
    

    That's good enough for Firefox. In Chrome you additionally need to replace the whitespace between the spans with an  . (Removing the whitespace doesn't work.)

提交回复
热议问题