我试图使一个页面与一些div水平对齐,我希望宽度调整的基础上的内容,所以我会得到一个水平滚动,如果内容大于屏幕尺寸。我有这个:
    <div>
    <div style="width: 300px; height: 300px; background-color: black; margin-left: 10px; float: left;"></div>
    <div style="width: 300px; height: 300px; background-color: black; margin-left: 10px; float: left;"></div>
    <div style="width: 300px; height: 300px; background-color: black; margin-left: 10px; float: left;"></div>
    <div style="width: 300px; height: 300px; background-color: black; margin-left: 10px; float: left;"></div>
    <div style="width: 300px; height: 300px; background-color: black; margin-left: 10px; float: left;"></div>
</div>子div并排对齐,但当达到屏幕大小时,它会断成一条新的线。有什么想法吗?
发布于 2014-03-16 21:39:56
我会和display: inline-block一起使用white-space: nowrap。
顺便说一句,尝试在HTML中使用CSS而不是内联样式。除非绝对必要,否则应避免使用内联样式。
<div class="row">
  <div></div>
  <div></div>
  <div></div>
  <div></div>
CSS:
.row {
  white-space: nowrap;
}
.row > div {
  width: 300px;
  display: inline-block;
}https://stackoverflow.com/questions/22437514
复制相似问题