【问题标题】:How to horizontal scroll square boxes in a mobile view in html/css?如何在 html/css 的移动视图中水平滚动方框?
【发布时间】:2018-11-03 01:46:08
【问题描述】:

我有一个在桌面视图上看起来很完美的网站。我还创建了fiddle,以便轻松进行更改。

我用来对齐一行中的正方形的 CSS 代码的 sn-ps 是:

.squares {
  display: flex;
  justify-content: space-between;
  align-items:center;
  padding: 1rem;
  flex-wrap: wrap;
}

.squares .square {
    width: 13%;
    text-align: center;
    height: 150px;
    padding-top: 1%;
    padding-left: 1%;
    padding-right: 1%;
    border-style: solid;
    border-width: 3px;
    border-color: rgb(145, 147, 150);
    border-radius: 10px;
   }



问题陈述:

我想知道应该添加或更改哪些 CSS 代码 here 以便我能够水平滚动方形框在移动视图中类似于以下内容截图:

此时,在移动视图中,它适合屏幕,但不能水平滚动

【问题讨论】:

    标签: html css responsive-design media-queries horizontal-scrolling


    【解决方案1】:

    尝试同时改变:

    .squares{
      flex-wrap: nowrap;
    }
    .squares .square{
      flex: 1 0 auto;
    }
    

    这可以防止方块进入第二行。

    【讨论】:

    • 我试过了,但我无法获得所需的屏幕截图。
    【解决方案2】:

    只需添加以下代码作为示例:

    CSS

    @media only screen and (max-width: 767px) {
    
        .squares {
            overflow-x: scroll;
            overflow-y: hidden;
            height: 200px;
            white-space:nowrap
        }
    
        .squares .square {
            width: 30%;
            text-align: center;
            height: 150px;
            display:inline-block; /* Added */
            margin-bottom: 11%;
            /*padding-top: 1%;
            padding-left: 1%;
            padding-right: 1%;*/
            border-style: solid;
            border-width: 3px;
            border-color: rgb(145,147,150);
            border-radius: 10px;
        }
    
    }
    

    HTML

    <div class="squares">
        <div class="square"></div>
        <div class="square"></div>
        <div class="square"></div>
        <div class="square"></div>
        <div class="square"></div>
    </div>
    

    【讨论】:

    • 我正在测试它并且它有效。你复制了css和html吗?
    • 一定要慢慢来。
    • 你能用我的例子作为你的基础html/css吗?
    • 那之后好吗?
    • 我确实有一个 fiddle 在移动视图中滚动,但我希望滚动在桌面视图中完全消失。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多