【问题标题】:HTML5 - Horizontally aligning Image and Table inlineHTML5 - 水平对齐图像和表格内联
【发布时间】:2017-03-07 18:38:29
【问题描述】:

我正在使用 Bootstrap,我想在同一列中“并排”对齐图像和表格。

HTML 代码:

    <div class="col-md-10" style="width: 100%"> 
       <img src="#"  class="img-responsive pull-left pro-page-pro-image">
        <div class="container">
       <table class="table table-responsive pull-right pro-page-contact-details-table">
         <tbody>
 <!---the table has 12 rows in total -->
            <tr>
              <td>MEMBER SINCE</td>
              <td>2007</td>
           </tr>
           <tr>
             <td>Suburb</td>
             <td>Fourways, Randburg</td>
           </tr>
        </tbody>
      </table>
    </div>
    </div>

相关CSS:

 .pro-page-pro-image {
  display:inline;
  margin-top: 4%;
  margin-left: 11%; 
  margin-right: 11%; 
  margin-bottom: 4%;
}
 .pro-page-contact-details-table {
  display: inline;
  }

.table.table-responsive 类是标准引导类。目前在浏览器中,表格位于图像的正下方(均左对齐),尽管尝试了很多方法,但我无法让它们并排对齐。

任何指针将不胜感激。

【问题讨论】:

    标签: html twitter-bootstrap css inline positioning


    【解决方案1】:

    我觉得应该是这样的:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    
    <div class="col-md-10" style="width: 100%">
      <div class="row">
        <div class="col-md-6">
          <img src="https://dummyimage.com/300x200/000/fff" class="img-responsive pull-left pro-page-pro-image">
        </div>
        <div class="col-md-6">
          <table class="table table-responsive pull-right pro-page-contact-details-table">
            <tbody>
              TABLE HERE
            </tbody>
          </table>
        </div>
      </div>
    </div>

    您需要使用 ROW 并在行中定义列。 6+6 = 最大 12,所以它现在应该对齐。如果你使用容器。它将使用屏幕的整个宽度,因此您无法对齐内容。

    【讨论】:

    • 谢谢 H. Brendan,您的建议解决了我的问题。赞赏。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多