如何使用Bootstrap网格创建此视图?还是应该使用列表组?

时间:2019-03-04 08:22:01

标签: css twitter-bootstrap user-interface bootstrap-4 bootstrap-grid

我使用了col-md-4,但“更多”按钮并未保持固定位置。我希望边框在移动视图中位于底部,在标签或桌面视图中如图所示。

     <div class="container-fluid">
            <div class="row">
                <div class="col-sm-4 col-12">
                    <div class="texts">
                        <h4>Latest News</h4>
                        <p>Lorem ipsum dolor sit amet, 
                            consectetur adipiscing elit. 
                            Suspendisse in metus mollis, 
                            tincidunt metus in, vulputate est. 
                            Donec ac aliquam augue. Vestibulum nec 
                            purus iaculis, placerat tortor eu, 
                            facilisis orci.
                        </p>
                    </div>
                    <button class="btn btn-primary">More</button>
                </div>
                <div class="col-sm-4 ">
                    <div class="texts">    
                        <h4>Feel free to Communicate</h4>
                        <p>Lorem ipsum dolor sit amet, 
                            consectetur adipiscing elit. 
                            Suspendisse in metus mollis, 
                            tincidunt metus in, vulputate est. 
                            Donec ac aliquam augue. Vestibulum nec 
                            purus iaculis, placerat tortor eu, 
                            facilisis orci.
                        </p>
                    </div>
                <button class="btn btn-primary">More</button>
            </div>
            <div class="col-sm-4">
                    <div class="texts">    
                        <h4>Our facilities</h4>
                        <p>Lorem ipsum dolor sit amet, 
                            consectetur adipiscing elit. 
                            Suspendisse in metus mollis, 
                            tincidunt metus in, vulputate est. 
                            Donec ac aliquam augue. Vestibulum nec 
                            purus iaculis, placerat tortor eu, 
                            facilisis orci.
                        </p>
                    </div>
                    <button class="btn btn-primary">More</button>
                </div>
            </div>
        </div>

Desktop View

Mobile View

2 个答案:

答案 0 :(得分:1)

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<style>
  .borderstyle{
  border-right: 1px solid #CCC;
  }
  @media (min-width: 992px) {
  .borderstyle{
    border-right :none
  }
  }

  
  media
</style>
  </head>
  <body><div class="container-fluid">
            <div class="row">
                <div class="col-sm-4 col-lg-12">
                    <div class="texts borderstyle">
                        <h4>Latest News</h4>
                        <p>Lorem ipsum dolor sit amet, 
                            consectetur adipiscing elit. 
                            Suspendisse in metus mollis, 
                            tincidunt metus in, vulputate est. 
                            Donec ac aliquam augue. Vestibulum nec 
                            purus iaculis, placerat tortor eu, 
                            facilisis orci.
                        </p>
                        <div class="row">
                          <div class="col">
                         <button class="btn btn-primary float-right">More</button>
                          </div>
                          </div>
                    </div>
                   
                    <hr class="d-none d-lg-block">
                </div>
                <div class="col-sm-4 col-lg-12">
                    <div class="texts borderstyle" >    
                        <h4>Feel free to Communicate</h4>
                        <p>Lorem ipsum dolor sit amet, 
                            consectetur adipiscing elit. 
                            Suspendisse in metus mollis, 
                            tincidunt metus in, vulputate est. 
                            Donec ac aliquam augue. Vestibulum nec 
                            purus iaculis, placerat tortor eu, 
                            facilisis orci.
                        </p>
                        <div class="row">
                          <div class="col">
                         <button class="btn btn-primary float-right">More</button>
                          </div>
                          </div>
                              <hr class="d-none d-lg-block">
                    </div>
               
            </div>
            <div class="col-sm-4 col-lg-12 borderstyle">
                    <div class="texts">    
                        <h4>Our facilities</h4>
                        <p>Lorem ipsum dolor sit amet, 
                            consectetur adipiscing elit. 
                            Suspendisse in metus mollis, 
                            tincidunt metus in, vulputate est. 
                            Donec ac aliquam augue. Vestibulum nec 
                            purus iaculis, placerat tortor eu, 
                            facilisis orci.
                        </p>
                        <div class="row">
                          <div class="col">
                         <button class="btn btn-primary float-right">More</button>
                          </div>
                          </div>
                              <hr class="d-none d-lg-block">
                    </div>
                    
                </div>
            </div>
        </div>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  </body>
</html>

您可以使用bootstrap类的float-right来将按钮向div的右侧按,对于边界,您可以结合使用“ hr标签”和在断点处可见的border类。

实现功能后,您可以根据需要美化html ...:)

答案 1 :(得分:1)

您只需要将css属性float:right添加到所有按钮

祝你好运!