CSS nowrap for other than text elements?

2020-08-09 08:41发布

问题:

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

回答1:

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



回答2:

You can set both these properties in CSS:

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



回答3:

You can declare static positions for the other contents using

position:absolute;


标签: css html nowrap