CSS nowrap for other than text elements?

2020-08-09 09:12发布

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

标签: css html nowrap
3条回答
何必那么认真
2楼-- · 2020-08-09 09:30

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

查看更多
smile是对你的礼貌
3楼-- · 2020-08-09 09:33

You can set both these properties in CSS:

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

查看更多
一纸荒年 Trace。
4楼-- · 2020-08-09 09:37

You can declare static positions for the other contents using

position:absolute;
查看更多
登录 后发表回答