使用Bootstrap设置div的样式

时间:2018-04-12 17:27:00

标签: html css twitter-bootstrap grid

我需要根据以下示例帮助调整我的div:

enter image description here

到目前为止我得到的是:

enter image description here

我不能在两个div之间应用间距,并且div的高度不同。

我的Html:

            <div class="container - fluid">
                    <div class="row" id="wrapper">
                        <div class="col-lg-8 col-md-8" id="columneone"> 
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

                        </div>

                        <div class="col-lg-4 col-md-4" id="columnetwo">
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

                    </div>
                    </div>
                </div>

我的CSS(我用得少):

#columneone{background-color:@deepblue !important; color:white !important;}
#columnetwo{background-color:@lightblue !important; color:white !important; }
#wrapper{margin-right:-173px; margin-left:-173px; padding-top: 10px}

1 个答案:

答案 0 :(得分:0)

您应该查看Bootstrap关于其Grid的文档,因为它可以让您更好地理解为什么您的初始尝试缺少背景颜色之间的水槽,以及您可以改进之前尝试的各种其他方法。

在Bootstrap 4中,我们可以利用一系列新的实用程序类以及flexbox网格来实现您期望的结果。

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<div class="container-fluid">
  <div class="row row-eq-height">
  
    <div class="col-8">
      <div class="bg-dark h-100 p-3">
        <p class="text-white">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      </div>
    </div>

    <div class="col-4">
      <div class="bg-secondary h-100 p-3">
        <p class="text-white">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      </div>
    </div>
    
  </div>
</div>

此处使用的颜色仅使用Bootstraps .bg-*实用程序类来提取,您需要对其进行调整以正确反映您的首选方案。