1

全屏我不想使用grid,我想显示 7,我想在移动时管理图像 2,2,2,1

我怎么能做这样的事情......

<div class="col-xs-6">
   <img src="banner1.png" alt="" class="banner-img">
</div>
<div class="col-xs-6">
   <img src="banner1.png" alt="" class="banner-img">
</div>

在我的 html 中看起来不错,但在移动时如何显示 2、2、2、1

<div class="container banner">
      <img src="banner1.png" alt="" class="banner-img">
      <img src="banner2.png" alt="" class="banner-img">
      <img src="banner3.png" alt="" class="banner-img">
      <img src="banner4.png" alt="" class="banner-img">
      <img src="banner5.png" alt="" class="banner-img">
      <img src=banner6.png" alt="" class="banner-img">
      <img src="banner7.png" alt="" class="banner-img">
    </div>
4

2 回答 2

1

基本上你需要做的是玩CSS。在 Css 中使用@media并设置移动屏幕的横幅宽度。下面是完整的工作示例:

.banner {
  background-color: red;
  text-align: center;
  vertical-align: middle;
  width: 100%;
  padding: 10px;
}

.banner-img {
  margin-top: 25px;
  margin-right: 5px;
  width: 100px;
  height: 100px;
}

@media only screen and (max-width: 500px) {
  .banner-img {
    width: 120px;
  }
}
<div class="banner">
  <div class="container banner">
    <img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
    <img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
    <img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
    <img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
    <img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
    <img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
    <img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
  </div>
</div>

您可以根据屏幕大小调整横幅宽度。享受!

于 2018-01-16T05:52:29.843 回答
0

我认为您实际上指出了自己的解决方案

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
  <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" ></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
  <style type="text/css">
   img{
    border:1px solid black;
   }
  </style>
</head>
<body>
  <div class="container banner">
    <div class="row">
      <div class="col-xs-6">
        <img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
      </div>
      <div class="col-xs-6">
        <img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
      </div>
      <div class="col-xs-6">
        <img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
      </div>
      <div class="col-xs-6">
        <img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
      </div>
      <div class="col-xs-6">
        <img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
      </div>
      <div class="col-xs-6">
        <img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
      </div>
      <div class="col-xs-6">
        <img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
      </div>
    </div>
  </div>
</body>
</html>

于 2018-01-16T05:00:28.743 回答