HTML中table标签的跨多行和多列布局方法

5 篇文章 0 订阅

先放一张布局效果效果图


在实现这一布局效果时,主要应用了rowspan、colspan跨行和跨列的属性布局。在所跨的行或者列,在其他行或者列中也是占位的。比如:第一项项目基本信息是跨过5行,因此在接下来的4行中,第一列已经是默认被占了,行中的td列是从第二列开始布局;最后一行,项目得分占据6列,因此第二个td实际对应的是该行的第七列。具体实现代码如下:

HTML布局代码:

<!-- 明细表 -->
  <div class="chartbox">
    <ul class="chartmenu">
      <li>模块</li>
      <li>一级类目</li>
      <li>评估标准满分</li>
      <li>项目得分</li>
      <li>子模块得分(%)</li>
      <li>权重</li>
      <li>*权重得分</li>
    </ul>
    <table cellpadding="0" cellspacing="0">
      <!-- 项目基本信息 -->
      <tbody>
        <tr rowspan="6" class="table-row">
          <th rowspan="5" class="table-name">项目基本信息</th>
          <td rowspan="1" class="table-first">项目基本概况</td>
          <td rowspan="1" class="table-all">-9-</td>
          <td rowspan="1" class="table-score">-9-</td>
          <td rowspan="6" class="table-get">83</td>
          <td rowspan="6" class="table-weight">0.8</td>
          <td rowspan="6" class="table-weiscore">26.4</td>
        </tr>
        <tr class="table-row">
          <td class="table-first">团队基本概况</td>
          <td class="table-all">9</td>
          <td class="table-score">9</td>
        </tr>
        <tr class="table-row">
          <td class="table-first">资本市场认可度</td>
          <td class="table-all">9</td>
          <td class="table-score">9</td>
        </tr>
        <tr class="table-row">
          <td class="table-first">项目宣传推广力度</td>
          <td class="table-all">9</td>
          <td class="table-score">9</td>
        </tr>
        <tr class="table-row">
          <td class="table-first">项目热度</td>
          <td class="table-all">9</td>
          <td class="table-score">9</td>
        </tr>
        <tr class="table-lastrow">
          <td class="table-null"></td>
          <td class="table-first">小计</td>
          <td class="table-all">9</td>
          <td class="table-score">9</td>
        </tr>
      </tbody>
      <!-- 项目团队评估 -->
      <tbody>
        <tr rowspan="6" class="table-row">
          <th rowspan="3" class="table-name">项目团队评估</th>
          <td rowspan="1" class="table-first">创始人背景信息</td>
          <td rowspan="1" class="table-all">-9-</td>
          <td rowspan="1" class="table-score">-9-</td>
          <td rowspan="4" class="table-get">83</td>
          <td rowspan="4" class="table-weight">0.8</td>
          <td rowspan="4" class="table-weiscore">26.4</td>
        </tr>
        <tr class="table-row">
          <td class="table-first">核心管理团队信息</td>
          <td class="table-all">9</td>
          <td class="table-score">9</td>
        </tr>
        <tr class="table-row">
          <td class="table-first">核心开发团队信息</td>
          <td class="table-all">9</td>
          <td class="table-score">9</td>
        </tr>
        <tr class="table-lastrow">
          <td class="table-null"></td>
          <td class="table-first">小计</td>
          <td class="table-all">9</td>
          <td class="table-score">9</td>
        </tr>
      </tbody>
      <!-- 项目方案评估 -->
      <tbody>
        <tr rowspan="6" class="table-row">
          <th rowspan="3" class="table-name">项目方案评估</th>
          <td rowspan="1" class="table-first">创始人背景信息</td>
          <td rowspan="1" class="table-all">-9-</td>
          <td rowspan="1" class="table-score">-9-</td>
          <td rowspan="4" class="table-get">83</td>
          <td rowspan="4" class="table-weight">0.8</td>
          <td rowspan="4" class="table-weiscore">26.4</td>
        </tr>
        <tr class="table-row">
          <td class="table-first">核心管理团队信息</td>
          <td class="table-all">9</td>
          <td class="table-score">9</td>
        </tr>
        <tr class="table-row">
          <td class="table-first">核心开发团队信息</td>
          <td class="table-all">9</td>
          <td class="table-score">9</td>
        </tr>
        <tr class="table-lastrow">
          <td class="table-null"></td>
          <td class="table-first">小计</td>
          <td class="table-all">9</td>
          <td class="table-score">9</td>
        </tr>
      </tbody>
      <!-- 合计 -->
      <tbody>
        <tr class="addtotal">
          <td colspan="2">合计</td>
          <td>240</td>
          <td colspan="3">240</td>
          <td>240</td>
        </tr>
        <tr class="totalscore">
          <td colspan="6">项目得分</td>
          <td>240</td>
        </tr>
      </tbody>
    </table>
  </div>

css样式代码:

.chartbox {
    width: 95%;
    margin: 0 auto;
    min-height: 300px;
  }

  .chartmenu {
    width: 100%;
    height: 50px;
    background-color: #f6fafd;
    letter-spacing: -0.5em;
    font-size: 0;
  }

  .chartmenu li {
    letter-spacing: normal;
    display: inline-block;
    vertical-align: top;
    font-size: 14px;
    line-height: 50px;
    color: #333;
    text-align: center;
  }

  .chartmenu li:nth-of-type(1) {
    width: 135px;
  }

  .chartmenu li:nth-of-type(2) {
    width: 185px;
  }

  .chartmenu li:nth-of-type(3) {
    width: 130px;
  }

  .chartmenu li:nth-of-type(4) {
    width: 110px;
  }

  .chartmenu li:nth-of-type(5) {
    width: 150px;
  }

  .chartmenu li:nth-of-type(6) {
    width: 100px;
  }

  .chartmenu li:nth-of-type(7) {
    width: 140px;
  }

  .table-row .table-name {
    width: 134px;
    vertical-align: middle;
    font-size: 14px;
    color: #333;
    border-left: 1px solid #c8e5fa;
  }

  .table-row .table-first {
    width: 183px;
    text-align: center;
    vertical-align: top;
    height: 44px;
    line-height: 44px;
    border-bottom: 1px solid #c8e5fa;
    border-left: 1px solid #c8e5fa;
    border-right: 1px solid #c8e5fa;
  }

  .table-row .table-all {
    width: 130px;
    text-align: center;
    vertical-align: top;
    height: 44px;
    line-height: 44px;
    border-bottom: 1px solid #c8e5fa;
  }

  .table-row .table-score {
    width: 108px;
    text-align: center;
    vertical-align: top;
    height: 44px;
    line-height: 44px;
    border-bottom: 1px solid #c8e5fa;
    border-left: 1px solid #c8e5fa;
    border-right: 1px solid #c8e5fa;
  }

  .table-row .table-get {
    width: 149px;
    text-align: center;
    vertical-align: middle;
    border-bottom: 1px solid #c8e5fa;
    border-right: 1px solid #c8e5fa;
  }

  .table-row .table-weight {
    width: 99px;
    text-align: center;
    vertical-align: middle;
    border-bottom: 1px solid #c8e5fa;
    border-right: 1px solid #c8e5fa;
  }

  .table-row .table-weiscore {
    width: 139px;
    text-align: center;
    vertical-align: middle;
    border-bottom: 1px solid #c8e5fa;
    border-right: 1px solid #c8e5fa;
  }

  .table-lastrow {
    height: 30px;
    line-height: 30px;
    background-color: #f6fafd;
    text-align: center;
  }

  .table-lastrow td:last-child {
    border-right: 1px solid #c8e5fa;
  }

  .table-lastrow td:first-child {
    border-left: 1px solid #c8e5fa;
  }

  .addtotal {
    height: 40px;
    line-height: 40px;
    text-align: center;
  }

  .addtotal td:nth-of-type(1) {
    border-left: 1px solid #c8e5fa;
    border-right: 1px solid #c8e5fa;
  }

  .addtotal td:nth-of-type(3) {
    border-left: 1px solid #c8e5fa;
    border-right: 1px solid #c8e5fa;
  }

  .addtotal td:last-child {
    border-right: 1px solid #c8e5fa;
  }

  .totalscore {
    height: 50px;
    background-color: #f6fafd;
    line-height: 50px;
    text-align: center;
    font-weight: 600;
  }

  .totalscore td {
    border-bottom: 1px solid #c8e5fa;
  }

  .totalscore td:nth-of-type(1) {
    border-left: 1px solid #c8e5fa;
    border-right: 1px solid #c8e5fa;
  }

  .totalscore td:nth-of-type(2) {
    border-right: 1px solid #c8e5fa;
  }
通过以上,就能达到本文开篇效果图的布局了。


### 回答1: table布局的优点包括: 1. 可以实现较复杂的布局,比如实现多行合并、多列合并等特殊效果; 2. 标签简单,易于理解和维护; 3. 可以用于实现页面的网格化布局; 4. 在某些情况下,表格优于div布局具有更好的语义化。 ### 回答2: Div(即HTML的 <div> 元素)和CSS样式表是前端网页开发必不可少的组成部分。相比之下,table布局已经逐渐被视为过时的设计方法。下面是div css布局的优点: 1. 更灵活的布局:使用 div css 可以轻松地创建复杂的网页布局。相比之下,table布局有许多限制,例如表格只能在行和列移动,无法灵活地组合内部元素。 2. 更好的可访问性:使用 div css 布局可以更好地满足辅助技术的需要,例如屏幕阅读器和语音控制。相比之下,table布局的可访问性较差,因为表格不易于阅读和使用辅助技术。 3. 更好的性能:相比之下,div css 布局通常比table布局更快。这是因为 table布局需要在每个单元格使用额外的HTML标记,但 div css 可以使用更小和更简单的HTML元素来达到布局目的,从而减少了页面的负载时间。 4. 更好的SEO:使用div css布局可以在页面上更好地定义内容的结构,从而使搜索引擎更容易理解页面的内容。相比之下,table布局可能会混淆搜索引擎,使搜索引擎难以准确地理解页面内容。 5. 更好的开发体验:使用div css布局可以使前端开发人员更方便地维护CSS样式表,因为CSS样式表可以更好地与HTML代码分离,更容易实现可重用的CSS样式表。而使用table布局会使代码更容易出现冗余,逻辑更难理解。 综上所述,使用div css布局可以提供更好的灵活性、可访问性、性能、SEO和开发体验。与table布局相比,它已经成为现代前端网页布局设计的标准方法。 ### 回答3: 随着网页设计的不断发展,CSS布局已经成为了一种必不可少的网页布局技术,而div CSS布局table布局在网页布局有着很大的不同。下面是div CSS布局table布局的比较: 1. 结构分离 div CSS布局能够将html结构进行分离,使得结构和表现完全分离,使得代码更易于维护,代码结构更加清晰,而table布局在实现上相对比较混乱,结构和表现没有完全分离,代码相对较为复杂。 2. 灵活性 div CSS布局能够根据不同的浏览器和不同的分辨率进行适应性布局,很方便制作响应式布局,而table布局因为其强制性布局,所以很难实现响应式布局。 3. 维护性 div CSS布局可以通过外部样式来改变所有页面的布局,而table布局则需要每个页面的布局都进行更改,这使得维护代码更加方便。 4. 语义化 div CSS布局可以使得网页设计更加具有语义化,使得网页更易于搜索引擎的搜寻,而table布局因为强制性布局,其代码结构和语义化相对比较弱。 综上所述,div CSS布局优于table布局的优点在于:更好的灵活性、结构分离,更易于维护,更加具有语义化,而table布局的优点在于兼容性较好,但其在实际应用已经被明显地取代。因此,在网页布局过程应该优先选择div CSS布局
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值