【问题标题】:How to keep elements on same line with overflow如何使元素与溢出保持在同一行
【发布时间】:2014-04-21 15:55:29
【问题描述】:

我正在尝试制作一个页面,其中一些 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 并排对齐,但当达到屏幕尺寸时,它会换行。有什么想法吗?

【问题讨论】:

    标签: html css resize width


    【解决方案1】:

    我会使用white-space: nowrapdisplay: inline-blockLive demo (click).

    顺便说一句,尝试在 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;
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-17
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 2017-08-07
    • 1970-01-01
    相关资源
    最近更新 更多