使用BS4在左侧和右侧排列卡片,而不使用父列

时间:2017-05-14 00:36:38

标签: twitter-bootstrap bootstrap-4 twitter-bootstrap-4

使用Bootstrap 4并且没有Javascript,如何在视口很大时创建这样的排列:     Large viewport card arrangement

视口受约束时的这种安排:     Small viewport card arrangement

我能让它看起来像大型视口布置的唯一方法就是这样做:

<div class="row justify-content-center">

  <div class="col-8 column-1">

    <form class="card text-center" action="runthis" method="GET">
      <div class="card-header">Hello</div>
      <div class="card-block">
        <input type="text" class="form-control input-lg" name="full_name" placeholder="Full Name" autofocus="" />
        <input type="text" class="form-control input-lg" name="full_name2" placeholder="Full Name/>
        <input type=" text " class="form-control input-lg " name="full_name3 " placeholder="Name " />
        <button name="Submit " value"submit " class="btn btn-primary ">Submit</button>
      </div>
    </form>

  </div> <!-- end column-1 -->

  <div class="col-4 column-2">
    <div class="card p-3">
      <blockquote class="card-block card-blockquote">
        <h4 class="card-title ">Card title</h4>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
      </blockquote>
    </div>
    <div class="card">
      <div class="card-block ">
        <h4 class="card-title ">Card title 2</h4>
        <p class="card-text ">This card has supporting text below as a natural lead-in to additional content.</p>
        <p class="card-text "><small class="text-muted ">Last updated 3 mins ago</small></p>
      </div>
    </div>
  </div>
</div>

您可以在 https://codepen.io/anon/pen/ZKoPWx

中看到此代码的实际效果

正如您从上面的代码中看到的那样,由于左侧和右侧部分的父列而导致视口受约束时,它不允许根据需要折叠。

如果没有父列,我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

使用新的BS 4实用程序类在较大的屏幕上相应地浮动列。然后,他们将在较小的(xs)屏幕上按自然顺序堆叠。

https://www.codeply.com/go/A6F3GT1xw8

<div class="container-fluid">
    <div class="row d-block">
        <div class="col-sm-4 float-sm-right">
            <div class="card p-3">
                card 2
            </div>
        </div>
        <div class="col-sm-8 float-sm-left">
            <form class="card text-center" action="runthis" method="GET">
               card 1
            </form>
        </div>
        <div class="col-sm-4 float-sm-left">
            <div class="card">
                <div class="card-block ">
                    card 3
                </div>
            </div>
        </div>
    </div>
</div>