亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Bootstrap 表未正確對齊

Bootstrap 表未正確對齊

忽然笑 2023-10-17 17:50:59
我使用 Bootstrap 創建了兩個表,它們的內容量相似。盡管如此,這兩個不同的表并沒有正確對齊。我希望這些表的列能夠像 MS Excel 中那樣正確對齊。顯示問題的代碼和圖片如下:<div class="container-fluid">  <table class="table table-striped table-dark">    <h1 class="table-headers">Education</h1>    <thead>      <tr>        <th scope="col">#</th>        <th scope="col">School</th>        <th scope="col">Years</th>        <th scope="col">Program</th>      </tr>    </thead>    <tbody>      <tr>        <th scope="row">1</th>        <td>Hacettepe University, Ankara</td>        <td>2010-2014</td>        <td>BA, Composition and Orchestral Conducting</td>      </tr>      <tr>        <th scope="row">2</th>        <td>Istanbul Technical University</td>        <td>2015-2020</td>        <td>Ph.D.(c), Orchestral Conducting</td>      </tr>    </tbody>  </table>  <table class="table table-striped table-dark">    <h1 class="table-headers">Experience</h1>    <thead>      <tr>        <th scope="col">#</th>        <th scope="col">Institution</th>        <th scope="col">Years</th>        <th scope="col">Position</th>      </tr>    </thead>    <tbody>      <tr>        <th scope="row">1</th>        <td>Hacettepe University, Ankara</td>        <td>2014-2015</td>        <td>Intern</td>      </tr>      <tr>        <th scope="row">2</th>        <td>Istanbul Technical University</td>        <td>2015-2020</td>        <td>Research Assistant</td>      </tr>    </tbody>  </table></div>
查看完整描述

2 回答

?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

您可以為此設置列寬:

table?th?{width:?10%}
table?td?{width:?30%}

順便說一句,您不能在表格內使用標題,而是可以使用caption元素并根據需要設置其樣式。

所以你的表可以看起來像這樣:

table th {width: 10%}

table td {width: 30%}

table caption {font-size: 2em; caption-side: top;}

<link rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<div class="container-fluid">

? <table class="table table-striped table-dark">

? ? <caption class="table-headers">Education</caption>

? ? <thead>

? ? ? <tr>

? ? ? ? <th scope="col">#</th>

? ? ? ? <th scope="col">School</th>

? ? ? ? <th scope="col">Years</th>

? ? ? ? <th scope="col">Program</th>

? ? ? </tr>

? ? </thead>

? ? <tbody>

? ? ? <tr>

? ? ? ? <th scope="row">1</th>

? ? ? ? <td>Hacettepe University, Ankara</td>

? ? ? ? <td>2010-2014</td>

? ? ? ? <td>BA, Composition and Orchestral Conducting</td>

? ? ? </tr>

? ? ? <tr>

? ? ? ? <th scope="row">2</th>

? ? ? ? <td>Istanbul Technical University</td>

? ? ? ? <td>2015-2020</td>

? ? ? ? <td>Ph.D.(c), Orchestral Conducting</td>

? ? ? </tr>

? ? </tbody>

? </table>

? <table class="table table-striped table-dark">

? ? <caption class="table-headers">Experience</caption>

? ? <thead>

? ? ? <tr>

? ? ? ? <th scope="col">#</th>

? ? ? ? <th scope="col">Institution</th>

? ? ? ? <th scope="col">Years</th>

? ? ? ? <th scope="col">Position</th>

? ? ? </tr>

? ? </thead>

? ? <tbody>

? ? ? <tr>

? ? ? ? <th scope="row">1</th>

? ? ? ? <td>Hacettepe University, Ankara</td>

? ? ? ? <td>2014-2015</td>

? ? ? ? <td>Intern</td>

? ? ? </tr>

? ? ? <tr>

? ? ? ? <th scope="row">2</th>

? ? ? ? <td>Istanbul Technical University</td>

? ? ? ? <td>2015-2020</td>

? ? ? ? <td>Research Assistant</td>

? ? ? </tr>

? ? </tbody>

? </table>

</div>


查看完整回答
反對 回復 2023-10-17
?
慕標5832272

TA貢獻1966條經驗 獲得超4個贊

為此,您需要將所有內容放入一張表中:


table {

width: 100%;

}

<div class="container-fluid">

  <table class="table table-striped table-dark">

    <h1 class="table-headers">Education</h1>

    <thead>

      <tr>

        <th scope="col">#</th>

        <th scope="col">School</th>

        <th scope="col">Years</th>

        <th scope="col">Program</th>

      </tr>

    </thead>

    <tbody>

      <tr>

        <th scope="row">1</th>

        <td>Hacettepe University, Ankara</td>

        <td>2010-2014</td>

        <td>BA, Composition and Orchestral Conducting</td>

      </tr>

      <tr>

        <th scope="row">2</th>

        <td>Istanbul Technical University</td>

        <td>2015-2020</td>

        <td>Ph.D.(c), Orchestral Conducting</td>

      </tr>

    </tbody>

    <h1 class="table-headers">Experience</h1>

    <thead>

      <tr>

        <th scope="col">#</th>

        <th scope="col">Institution</th>

        <th scope="col">Years</th>

        <th scope="col">Position</th>

      </tr>

    </thead>

    <tbody>

      <tr>

        <th scope="row">1</th>

        <td>Hacettepe University, Ankara</td>

        <td>2014-2015</td>

        <td>Intern</td>

      </tr>

      <tr>

        <th scope="row">2</th>

        <td>Istanbul Technical University</td>

        <td>2015-2020</td>

        <td>Research Assistant</td>

      </tr>

    </tbody>

  </table>

</div>

PS:你所擁有的與CSS表格無關,而是常規的HTML表格。



查看完整回答
反對 回復 2023-10-17
  • 2 回答
  • 0 關注
  • 211 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號