bootstrap-4 - Bootstrap 4 - 如何 colspan 和 rowspan

标签 bootstrap-4 css-tables

我有这个 bootstrap 4 表,它的行为不像我预期的那样

或者我可能误解了 bootstrap 4 表标签的含义

你能提示一下有什么问题吗?

这是 fiddle https://jsfiddle.net/1uokLh67/11/

例如如您所见,他们 支付给 客户 单元格每个单元格都没有跨越 50%,但最后有一些空白区域,您会看到其他行为

谢谢

  <div class="container">
    <table class="table table-bordered">
    	 <caption>A complex table</caption>
       
       
    		 <thead>
    				<tr>
    					<th class="col-4">Invoice #123456789</th>
    					<th class="col-2">Date:</th>
    					<th class="col-6">14 January 2025</th>
    				</tr>
    			  <tr>
    			   <td class="col-6">
    			    <strong>Pay to:</strong><br>
    			    Acme Billing Co.<br>
    			    123 Main St.<br>
    			    Cityville, NA 12345
    			   </td>
    			   <td class="col-6">
    			    <strong>Customer:</strong><br>
    			    John Smith<br>
    			    321 Willow Way<br>
    			    Southeast Northwestershire, MA 54321
    			   </td>
    			  </tr>
    		 </thead>
         
         
    		 <tbody>
    			  <tr>
              <th class="col-3">Qty.</th>			  	
              <th class="col-3">Name / Description</th>
              <th class="col-3">Price</th>
              <th class="col-3">Cost</th>
    			  </tr>
    			  <tr>
                <td class="col-3">1000</td>
                <td class="col-3">Paperclips</td>			   
                <td class="col-3">0.01</td>
                <td class="col-3">10.00</td>
    			  </tr>
    			  <tr>
    			   <td class="col-3">100</td>			  	
    			   <td class="col-3">Staples (box)</td>
    			   <td class="col-3">1.00</td>
    			   <td class="col-3">100.00</td>
    			  </tr>
    		 </tbody>
    		 <tfoot>   
    			  <tr>
              <td  class="col-3"></td>
              <td class="col-3"></td>
              <th class="col-3">Subtotal</th>
              <td class="col-3"> 110.00</td>
    			  </tr>
    			  <tr>
              <td class="col-3"></td>
              <th class="col-3">Tax</th>
              <td class="col-3"> 8% </td>
              <td class="col-3">8.80</td>
    			  </tr>
    			  <tr>
              <td class="col-3"></td>
              <td class="col-3"></td>
              <th class="col-3">Grand Total</th>
              <td class="col-3">$ 118.80</td>
    			  </tr>
    		 </tfoot>
         
    		</table>
        </div>

最佳答案

使用 colspan 来解决您的问题...

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
  <table class="table table-bordered">
    <caption>A complex table</caption>
    <thead>
      <tr>
        <th class="col-4">Invoice #123456789</th>
        <th class="col-2">Date:</th>
        <th class="col-6" colspan="2">14 January 2025</th>
      </tr>
      <tr>
        <td class="col-6" colspan="1">
          <strong>Pay to:</strong>
          <br>
          Acme Billing Co.<br>
          123 Main St.<br>
          Cityville, NA 12345
        </td>
        <td class="col-6" colspan="3">
          <strong>Customer:</strong>
          <br>
          John Smith<br>
          321 Willow Way<br>
          Southeast Northwestershire, MA 54321
        </td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th class="col-3">Qty.</th>
        <th class="col-3">Name / Description</th>
        <th class="col-3">Price</th>
        <th class="col-3">Cost</th>
      </tr>
      <tr>
        <td class="col-3">1000</td>
        <td class="col-3">Paperclips</td>
        <td class="col-3">0.01</td>
        <td class="col-3">10.00</td>
      </tr>
      <tr>
        <td class="col-3">100</td>
        <td class="col-3">Staples (box)</td>
        <td class="col-3">1.00</td>
        <td class="col-3">100.00</td>
      </tr>
    </tbody>
    <tfoot>
      <tr>
        <td class="col-3"></td>
        <td class="col-3"></td>
        <th class="col-3">Subtotal</th>
        <td class="col-3"> 110.00</td>
      </tr>
      <tr>
        <td class="col-3"></td>
        <th class="col-3">Tax</th>
        <td class="col-3"> 8% </td>
        <td class="col-3">8.80</td>
      </tr>
      <tr>
        <td class="col-3"></td>
        <td class="col-3"></td>
        <th class="col-3">Grand Total</th>
        <td class="col-3">$ 118.80</td>
      </tr>
    </tfoot>
  </table>
</div>

关于bootstrap-4 - Bootstrap 4 - 如何 colspan 和 rowspan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55276665/

相关文章:

html - 如何将 table th 元素与 bootstrap v4.1 表中的 td 元素对齐?

html - 试图在 bootstrap 4 中将导航链接与 Logo 对齐

html - 如何将大于其容器的字符居中

jQuery:如何同步表格单元格/行高

html - 使用 css "display: table"属性复制的表格中的表格

html - 顶部和底部的 Bootstrap 4 字段集图例字段

html - Dropdown Bootstrap 4 在 angular 应用程序的生产中不起作用

javascript - Bootstrap 日期时间选择器步进不起作用

html - 两个 div 并排设置为显示 : table-cell, 但第二列中的文本正在下拉

html - 表格中的表格未正确显示(奇怪的间距)