Bootstrap Scaffolding

大兔子大兔子 提交于 2021-02-07 10:44:54

问题


Hello I am currently trying to figure out how to get two classes to float side by side while using Bootstrap, What I wish to accomplish is to get my text to float to the left and image float to the right! Here is my code:

 <div class="row-fluid">
  <div id="test-1" class="span6"></div>
  <div id="test-2" class="span6"></div>
</div>

body {
  background-color: black;
}
#test-1 {
  background-color: white;
  height: 200px;
  width: 200px;
}
#test-2 {
  background-image: url("http://www.rd.com/wp-content/uploads/sites/2/2016/04/01-cat-wants-to-tell-you-laptop.jpg");
  background-size: cover;
  background-repeat: no-repeat;
  height: 200px;
  width: 200px;
}

回答1:


You can use both pull-left & pull-right or col-xs-6, depending upon what exactly you want to achieve.

Here's the code followed by jsfiddle link showing both things done:

    body {
      background-color: black;
    }
    #test-1 {
      background-color: white;
      height: 200px;
      width: 200px;
    }
    #test-2 {
      background-image: url("http://www.rd.com/wp-content/uploads/sites/2/2016/04/01-cat-wants-to-tell-you-laptop.jpg");
      background-size: cover;
      background-repeat: no-repeat;
      height: 200px;
      width: 200px;
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

    <div class="row-fluid">
          <div id="test-1" class="span6 pull-left"></div>
          <div id="test-2" class="span6 pull-right"></div>
        </div>
        
        <div class="clearfix"></div>
        
        <div class="row-fluid">
          <div id="test-1" class="span6 col-xs-6"></div>
          <div id="test-2" class="span6 col-xs-6"></div>
        </div>

Jsfiddle link: https://jsfiddle.net/jLfcpssz/




回答2:


bootstrap has a class called pull-right and pull-left I think those may work for you

body {
  background-color: black!important;
}
#test-1 {
  background-color: white;
  height: 200px;
  width: 200px;
}
#test-2 {
  background-image: url("http://www.rd.com/wp-content/uploads/sites/2/2016/04/01-cat-wants-to-tell-you-laptop.jpg");
  background-size: cover;
  background-repeat: no-repeat;
  height: 200px;
  width: 200px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="container">
  <div class="row">
    <div id="test-1" class="col-md-6 span6 pull-left"></div>
    <div id="test-2" class="col-md-6 span6 pull-right"></div>
  </div>
</div>


来源:https://stackoverflow.com/questions/42074944/bootstrap-scaffolding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!