1

不太清楚发生了什么。当我减小浏览器的宽度时,列应该转到下一行,但相反,它们会相互重叠,为什么?

它与我命名列类的方式有关吗?有三个,所以我为每个都放了 col-4。当浏览器的宽度变小时,他们为什么不转到下一行?

<html>
  <head>
    <link rel="stylesheet" href="css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" type='text/css'>
  </head>
  <body>
    <div class="row">
      <div class="col-4">
        <div class="btn-group btn-group-toggle" data-toggle="buttons">
          <label class="btn btn-primary active">
            <input type="radio" name="options" id="option1" autocomplete="off" checked> Test
          </label>
          <label class="btn btn-primary">
            <input type="radio" name="options" id="option2" autocomplete="off"> Test
          </label>
          <label class="btn btn-primary">
            <input type="radio" name="options" id="option3" autocomplete="off"> Test
          </label>
          <label class="btn btn-primary">
            <input class="btn-light" type="radio" name="options" id="option4" autocomplete="off"> Test
          </label>   
        </div>
      </div>
      <div class="col-4">
        <span class="main">Date</label>
          <input id="dashboardDatePick" type="date" name="date">
        </div>
        <div class="col-4">
          <span class="main">Date 2</label>
          <input id="dashboardTimePick" type="date" name="time">
        </div>
      </div>
    <script src="js/jquery-3.2.1.js"></script>
    <script src="js/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <script src="js/main.js"></script>
  </body>
</html> 
4

3 回答 3

1

此处使用的 Bootstrap 内置类应该是:

.col-md-4

并不是

.col-4

请将所有出现的 .col-4 更改为 .col-md-4 以获得您想要的结果。

编辑:这会将中等屏幕尺寸设置为一个断点,在该断点下方 div 将占据屏幕宽度的 100%,因此三个 div 将彼此堆叠在一起。

于 2018-06-28T09:07:38.973 回答
1

如果你想让他们断线,你必须定义他们从什么尺寸的屏幕上width

您设置了它设置的所有屏幕尺寸的col-4含义( )col-4width:33.33%

正如您所说,您希望他们刹车线是您需要声明尺寸的原因;

例如:

col-md-4

→ 从 md 向上设置width:33.33%( 12/4=3 => 100%:3=33.33%) 并从 md 向下 ( 表示smxs) 它设置width:100%

在此处了解更多信息:https ://getbootstrap.com/docs/4.0/layout/grid/

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
 <div class="container">
<div class="row">
            <div class="col-md-4">

                <div class="btn-group btn-group-toggle" data-toggle="buttons">
                  <label class="btn btn-primary active">
                    <input type="radio" name="options" id="option1" autocomplete="off" checked> Test
                  </label>
                  <label class="btn btn-primary">
                    <input type="radio" name="options" id="option2" autocomplete="off"> Test
                  </label>
                  <label class="btn btn-primary">
                    <input type="radio" name="options" id="option3" autocomplete="off"> Test
                  </label>
                  <label class="btn btn-primary">
                    <input class="btn-light" type="radio" name="options" id="option4" autocomplete="off"> Test
                  </label>   
                </div>

            </div>

            <div class="col-md-4">
                <span class="main">Date</label>
                <input id="dashboardDatePick" type="date" name="date">
            </div>

            <div class="col-md-4">
                <span class="main">Date 2</label>
                <input id="dashboardTimePick" type="date" name="time">
            </div>                          

    </div>
 </div>

笔记!

bootstrap 4 删除xs大小的意思col-*是从xs和向上

于 2018-06-28T09:07:25.020 回答
-1

在最新的 Bootstrap 4 版本中,col-4 代表所有设备的宽度为 33.33%。除了使用 col-4,您还可以使用 col-lg-4 或 col-md-4 在响应式设计中获得您想要的结果。

<html>

    <head>

        <link rel="stylesheet" href="css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" type='text/css'>

    </head>

    <body>

        <div class="row">
            <div class="col-lg-4">

                <div class="btn-group btn-group-toggle" data-toggle="buttons">
                  <label class="btn btn-primary active">
                    <input type="radio" name="options" id="option1" autocomplete="off" checked> Test
                  </label>
                  <label class="btn btn-primary">
                    <input type="radio" name="options" id="option2" autocomplete="off"> Test
                  </label>
                  <label class="btn btn-primary">
                    <input type="radio" name="options" id="option3" autocomplete="off"> Test
                  </label>
                  <label class="btn btn-primary">
                    <input class="btn-light" type="radio" name="options" id="option4" autocomplete="off"> Test
                  </label>   
                </div>

            </div>

            <div class="col-lg-4">
                <span class="main">Date</label>
                <input id="dashboardDatePick" type="date" name="date">
            </div>

            <div class="col-lg-4">
                <span class="main">Date 2</label>
                <input id="dashboardTimePick" type="date" name="time">
            </div>                          

    </div>

        <script src="js/jquery-3.2.1.js"></script>
        <script src="js/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
        <script src="js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

        <script src="js/main.js"></script>

    </body>
</html> 

于 2018-06-28T09:42:44.450 回答