HTML+CSS: How to force div contents to stay in one line?

后端 未结 10 1990
小蘑菇
小蘑菇 2020-11-30 17:52

I have a long text inside a div with defined width:

HTML:

Stack Overflow is the BEST !!!

CSS:



        
10条回答
  •  悲哀的现实
    2020-11-30 18:25

    Everybody jumped on this one!!! I too made a fiddle:

    http://jsfiddle.net/audetwebdesign/kh4aR/

    RobAgar gets a point for pointing out white-space:nowrap first.

    Couple of things here, you need overflow: hidden if you don't want to see the extra characters poking out into your layout.

    Also, as mentioned, you could use white-space: pre (see EnderMB) keeping in mind that pre will not collapse white space whereas white-space: nowrap will.

提交回复
热议问题