无法在引导卡中添加两列

时间:2019-01-30 20:53:07

标签: twitter-bootstrap bootstrap-4

我正在尝试在卡片内添加两列:

<div class="card bg-white black-content">
  <div class="card-body">
    <div class="col-xs-12 col-sm-6">
      <label>test</label>
    </div>
    <div class="col-xs-12 col-sm-6">
       <label>test2</label>
    </div>
  </div>
</div>

问题是test2不在test的右侧,而是在底部(它们彼此堆叠),似乎Bootstrap创建了两个{ {1}}。我在做什么错了?

请注意,rows只是一个例子,我里面还有其他内容

3 个答案:

答案 0 :(得分:3)

为什么要用label关闭</test>标签?另外,您需要一个row才能在其中放置列

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="card bg-white black-content">
  <div class="card-body">
    <div class="row">
      <div class="col-12 col-sm-6">
        <label>test</label>
      </div>
      <div class="col-12 col-sm-6">
        <label>test2</label>
      </div>
    </div>
  </div>
</div>

答案 1 :(得分:2)

就像其他人所说的那样,所有列都需要用<div class="row"></div>元素包装。另外,请注意,col-xs-*Bootstrap 4上不再可用,相反,您必须使用col-*。无论如何,在您的示例中,这是多余的……因为列将采用所有12个可用列,以使断点低于lowest-specified(断点为SM)。 / p>

<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.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>

<div class="card bg-white black-content">
  <div class="card-header text-center">
    CARD
  </div>
  <div class="card-body">
  <div class="row">
      <div class="col-sm-6 bg-info text-center">
         <label>test</label>
      </div>
      <div class="col-sm-6 bg-warning text-center">
        <label>test2</label>
      </div>
  </div>
  </div>
</div>

答案 2 :(得分:1)

您忘记添加<div class="row">来包装您的列:

<div class="card bg-white black-content">
    <div class="card-body">
      <div class="row">
        <div class="col-xs-12 col-sm-6">
           <label>test</label>
        </div>
        <div class="col-xs-12 col-sm-6">
           <label>test2</label>
        </div>
      </div>
    </div>
</div>