CSS滚动水平分割

.group {
  background: #000;
  margin-left: 25px;
  margin-right: 25px;
  padding: 15px;
  width: inherit;
  white-space: nowrap;
  overflow-x: auto;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
}

.item{
  margin: 3px;
  background-color: #ddd;
  float: left;
  padding: 20px;
  width: 200px;
  height: 300px;
}

<div class="group">

 <div class="item">
  <img src="someimage1.png" alt="..." style="height:150px;">
  <div>
    <h5>Some Text</h5>
    <p>Description</p>
  </div>
 </div>

 <div class="item">
  <img src="someimage2.png" alt="..." style="height:150px">
  <div>
    <h5>Some Text</h5>
    <p>Description</p>
  </div>
 </div>

 <div class="item">
  <img src="someimage3.png" alt="..." style="height:150px">
  <div>
    <h5>Some Text</h5>
    <p>Description</p>
  </div>
 </div>

</div>

顶行有2个项目,下一个项目转到下一行而不是同一行。我希望所有3行与水平滚动在同一行。我以为float:left正在影响滚动,但是删除将导致所有3个划分都位于单独的行中

评论
Carr
Carr

尝试这个:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <style>
    .container {
      overflow-x: auto;
      background: #000;
      border-bottom-left-radius: 10px;
      border-bottom-right-radius: 10px;
    }

    .group {
      margin-left: 25px;
      margin-right: 25px;
      padding: 15px;
      width: 600px;
      display: flex
    }

    .item{
      margin: 3px;
      background-color: #ddd;
      padding: 20px;
      width: 200px;
      height: 300px;
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="group">

     <div class="item">
      <img src="someimage1.png" alt="..." style="height:150px;">
      <div>
        <h5>Some Text</h5>
        <p>Description</p>
      </div>
     </div>

     <div class="item">
      <img src="someimage2.png" alt="..." style="height:150px">
      <div>
        <h5>Some Text</h5>
        <p>Description</p>
      </div>
     </div>

     <div class="item">
      <img src="someimage3.png" alt="..." style="height:150px">
      <div>
        <h5>Some Text</h5>
        <p>Description</p>
      </div>
     </div>
    </div>
  </div>
</body>
</html>
点赞
评论