I have a long text inside a div with defined width:
HTML:
Stack Overflow is the BEST !!!
CSS:
Give this a try. It uses pre rather than nowrap as I would assume you would want this to run similarly to <pre> but either will work just fine:
div {
border: 1px solid black;
max-width: 70px;
white-space:pre;
}
http://jsfiddle.net/NXchy/11/
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.
Try this:
div {
border: 1px solid black;
width: 70px;
overflow: hidden;
white-space: nowrap;
}
Use white-space:nowrap and overflow:hidden
http://jsfiddle.net/NXchy/8/