在移动视图中更改页面时 bootstrap 网格列顺序

change bootstrap grid column order when page in mobile view

我有一个 html 页面,其中一行有 4 列。当我在桌面视图中加载页面时,我可以完美地看到所有四列,但是当我在移动视图中检查相同内容时,所有 div 都一一显示。

我需要在移动视图中每行显示两列。

例如:桌面视图

[a][b][c][d]

手机浏览:

[a][b]

[c][d]

我目前正在使用 bootstrap 版本 3.3.7。

以下是完整的html:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="text/javascript"></script>
     <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" type="text/javascript"></script> -->
    
<script type="text/javascript">


</script>
<style type="text/css">
.site-footer
{
  background-color:#26272b;
  padding:45px 0 20px;
  font-size:15px;
  line-height:24px;
  color:#737373;
}
.alert {
   width:108px;
}
</style>
</head>
<body>

  <div class="container">
  <div class="row">
        <div class="col-sm-3">
           <div class="alert alert-info">a</div>
        </div>
        <div class="col-sm-3">
           <div class="alert alert-danger">b</div>
        </div>
        <div class="col-sm-3">
            <div class="alert alert-info">c</div>
       </div>
        <div class="col-md-3">
           <div class="alert alert-info">d</div>
       </div>
     </div>
     
   
  
</div>
</body>
<script>


</script>
</html>

求推荐。

在bootstrap3中,您可以使用col-xs-在手机屏幕上制作栏目。

下面的代码在平板电脑和手机上生成 2 列,在大屏幕上生成 4 列:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

<div class="container">
 <div class="row">
   <div class="col-xs-6 col-md-3">
     <div class="alert alert-info">a</div>
   </div>
   <div class="col-xs-6 col-md-3">
     <div class="alert alert-danger">b</div>
   </div>
   <div class="col-xs-6 col-md-3">
     <div class="alert alert-info">c</div>
   </div>
   <div class="col-xs-6 col-md-3">
     <div class="alert alert-info">d</div>
   </div>
 </div>
</div>

Bootstrap 3、我们在移动设备上使用col-xs-制作栏目

<!DOCTYPE html>
 <html lang="en">
   <head>
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

   <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="text/javascript"></script>
   <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" type="text/javascript"></script> -->

  
  </head>
<body>

<div class="container">
    <div class="row">
        <div class="col-xs-6 col-sm-3">
          <div class="alert alert-info">a</div>
         </div>
        <div class="col-xs-6 col-sm-3">
          <div class="alert alert-danger">b</div>
        </div>
        <div class="col-xs-6 col-sm-3">
          <div class="alert alert-info">c</div>
        </div>
       <div class="col-xs-6 col-md-3">
         <div class="alert alert-info">d</div>
       </div>
     </div>
  </div>
</body>