CSS nowrap for other than text elements?
Asked Answered
A

3

27

Is there a way to avoid wrapping of a div's content when the content is not just text e.g. several buttons?

Alitta answered 6/4, 2013 at 23:56 Comment(4)
do you mean overflow: hidden? Please let as know what "wrapping" meansOppress
"wrapping" means that white-space:nowrap; doesn't work for non-text, content gets wrapped (takes more than 1 line)Alitta
Please show a case where white-space: nowrap does not work for buttons. Button elements are text content, in HTML and CSS terms.Billion
If it doesn't work try to add display: inline-block to the elements that still wrap. It should follow the white-space: nowrap rule. I'm instead facing the problem of having it also to not overflow but resize the parent element.Cartilage
W
45

white-space:nowrap; should do the trick.

#foo {
  white-space:nowrap;
  width: 100px;
}
<div id="foo">
  <input type="button" value="hello"/>
  <input type="button" value="hello"/>
  <input type="button" value="hello"/>
  <input type="button" value="hello"/>
  <input type="button" value="hello"/>
  <input type="button" value="hello"/>
  <input type="button" value="hello"/>
</div>

Demo

Windowpane answered 6/4, 2013 at 23:59 Comment(1)
Demo doesn't work in my browser (Chrome 60.0.3112.113). I had to add "overflow:hidden" to "#foo".Twink
A
0

You can set both these properties in CSS:

white-space:nowrap; and max-width:something;

Aurore answered 7/4, 2013 at 0:2 Comment(0)
C
-3

You can declare static positions for the other contents using

position:absolute;
Channa answered 7/4, 2013 at 0:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.