简体   繁体   English

引导 3 框布局无响应

[英]bootstrap 3 box layout not responsive

I am trying to make a bootstrap4 layout that has 3 boxes side by side on a wide screen, but if the screen gets thinner I want the red/green boxes to always stay next to each other, and the far right blue box to move below the first two boxes like so in this pic:我正在尝试制作一个在宽屏幕上并排有 3 个框的 bootstrap4 布局,但是如果屏幕变薄,我希望红色/绿色框始终彼此相邻,最右边的蓝色框移动到下方在这张照片中,前两个盒子是这样的:

在此处输入图像描述

I'm new to the bootstrap4 column layout, and I've been working on trying to achieve this but my current work in progress code does not have the responsiveness I want:我是 bootstrap4 列布局的新手,我一直在努力实现这一目标,但我当前正在进行的工作代码没有我想要的响应能力:

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> <div class="container"> <div class="row"> <div style="background:red" class="col-md-3"> TEXT1 <br> TEXT1 <br> TEXT1 <br> TEXT1 <br> TEXT1 <br> TEXT1 <br> </div> <div style="background:green" class="col-md-3"> TEXT2 <br> TEXT2 <br> TEXT2 <br> TEXT2 <br> TEXT2 <br> TEXT2 <br> TEXT2 <br> </div> <div style="background:blue" class="col-md-3"> TEXT3 <br> TEXT3 <br> TEXT3 <br> </div> </div> </div>

Any help much appreciated, thanks非常感谢任何帮助,谢谢

You can add multiple col-* classes to your elements.您可以向元素添加多个col-*类。 This way you can set multiple different layouts for different screen sizes.通过这种方式,您可以为不同的屏幕尺寸设置多种不同的布局。

For example, you'll want 2 columns side by side and 1 full width on smaller screens.例如,您需要 2 个并排的列和 1 个全宽在较小的屏幕上。 Bootstrap is considered mobile first so start off with the smaller layouts and work your way up. Bootstrap 被认为是移动优先的,所以从较小的布局开始,然后逐步向上。 The smallest screen columns are defined with col-* (without any sm or md , etc).最小的屏幕列用col-*定义(没有任何smmd等)。

<div class="col-6"></div>
<div class="col-6"></div>
<div class="col-12"></div>

The two columns will each be 1/2 starting from the smallest screen size to the largest.从最小屏幕尺寸到最大屏幕尺寸,这两列各为1/2 The third div will be 1/1 of the width.第三个 div 将是宽度的1/1 Now to make your layout more complex, you can added classes to the elements, like having them become 1/3 of the width of a row on a larger screen.现在为了让你的布局更复杂,你可以给元素添加类,比如让它们在大屏幕上变成一行宽度的1/3

<div class="col-6 col-md-4"></div>
<div class="col-6 col-md-4"></div>
<div class="col-md-4"></div>

This will put all three columns in a single row on larger screens.这会将所有三列放在更大的屏幕上的一行中。 They are all 1/3 the width so they will fit together.它们都是宽度的1/3 ,因此它们可以组合在一起。 Note that col-12 has been removed.请注意, col-12已被删除。 This is because col-md-4 will imply the usage of col-12 when the screen is smaller than its breakpoint.这是因为当屏幕小于断点时col-md-4将暗示使用col-12

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> <div class="container"> <div class="row"> <div style="background:red" class="col-6 col-md-4"> TEXT1 <br> TEXT1 <br> TEXT1 <br> TEXT1 <br> TEXT1 <br> TEXT1 <br> </div> <div style="background:green" class="col-6 col-md-4"> TEXT2 <br> TEXT2 <br> TEXT2 <br> TEXT2 <br> TEXT2 <br> TEXT2 <br> TEXT2 <br> </div> <div style="background:blue" class="col-md-3"> TEXT3 <br> TEXT3 <br> TEXT3 <br> </div> </div> </div>

If you have any questions, please comment below.如果您有任何问题,请在下方发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM