How do I prevent DIV tag starting a new line?

后端 未结 9 1834
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 18:42

I want to output a single line of text to the browser that contains a tag. When this is rendered it appears that the DIV causes a new line. How can I include the content in

相关标签:
9条回答
  • 2020-12-04 19:30

    The div tag is a block element, causing that behavior.

    You should use a span element instead, which is inline.

    If you really want to use div, add style="display: inline". (You can also put that in a CSS rule)

    0 讨论(0)
  • 2020-12-04 19:31

    I am not an expert but try white-space:nowrap;

    The white-space property is supported in all major browsers.

    Note: The value "inherit" is not supported in IE7 and earlier. IE8 requires a !DOCTYPE. IE9 supports "inherit".

    0 讨论(0)
  • 2020-12-04 19:31

    A better way to do a break line is using span with CSS style parameter white-space: nowrap;

    span.nobreak {
      white-space: nowrap;
    }
    
    or
    span.nobreak {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    

    Example directly in your HTML

    <span style='overflow:hidden; white-space: nowrap;'> YOUR EXTENSIVE TEXT THAT YOU CAN´T BREAK LINE ....</span>
    
    0 讨论(0)
提交回复
热议问题