【问题标题】:HTML Table template headerHTML 表格模板标题
【发布时间】:2020-04-02 15:38:37
【问题描述】:

我有几个使用相同标题行的 HTML 表格。

<tr>
  <th width = "70%">Heading 1</th>
  <th width = "12%">Heading 2</th>
  <th width = "9%"><img src='/images/img1.png' height=25 width=25></th>
  <th width = "9%"><img src='/images/img2.png' height=25 width=25></th>
</tr>  

有没有办法为可以跨多个表的用户创建可重复使用的标题模板?就像创建一个类并将其分配给

提前感谢您的任何指导。

【问题讨论】:

    标签: html css templates html-table


    【解决方案1】:

    是的,您可以使用 classes 来执行此操作,并通过 JSAngular 或任何您想要的方式传递 HTML 中的值

    .table-box{
      width: 100%;
    }
    .table-box tr th:nth-child(1){
      width: 70%;
    }
    .table-box tr th:nth-child(2){
      width: 12%;
    }
    .table-box tr th:nth-child(3),
    .table-box tr th:nth-child(4){
      width: 9%;
    }
    <table class="table-box">
      <tr>
        <th >Heading 1</th>
        <th >Heading 2</th>
        <th ><img src='/images/img1.png' height=25 width=25></th>
        <th ><img src='/images/img2.png' height=25 width=25></th>
    </tr>  
      
    </table>

    【讨论】:

    • 我可以在课堂上添加值吗?即 Heading1, img src
    • 你能详细说明你所说的价值是什么意思吗?如果您在谈论数据,请告诉我您使用哪种语言作为后端
    • 没有数据。我正在使用 Javascript,我在这方面没问题。我有 4 个具有相同标题但数据不同的表。我希望找到一种方法来设置列名的样式和填充列名,并将其作为模板重复使用 4 次,而不是复制和粘贴 4 次。
    • 您不需要复制和粘贴,只需使用循环从数组列表中获取数据并在“th”中调用它
    猜你喜欢
    • 2020-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 2013-02-26
    相关资源
    最近更新 更多