html - CSS使表格自动从thead变成一列标签

标签 html css

CSS将多列表格合并为一列时,如何制作标签 哪些数据会根据广告信息自动创建?

This article当屏幕变为时,即将将多列表格变成一列 狭窄的。但是“标记数据”部分是硬编码的。

/*
Label the data
*/
td:nth-of-type(1):before { content: "First Name"; }
td:nth-of-type(2):before { content: "Last Name"; }
td:nth-of-type(3):before { content: "Job Title"; }
td:nth-of-type(4):before { content: "Favorite Color"; }
td:nth-of-type(5):before { content: "Wars of Trek?"; }
td:nth-of-type(6):before { content: "Porn Name"; }
td:nth-of-type(7):before { content: "Date of Birth"; }
td:nth-of-type(8):before { content: "Dream Vacation City"; }
td:nth-of-type(9):before { content: "GPA"; }
td:nth-of-type(10):before { content: "Arbitrary Data"; }

我们能否自动从广告中获取标签并在此处使用它们,而不是硬编码?

<thead>
<tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Job Title</th>
    <th>Favorite Color</th>
    <th>Wars or Trek?</th>
    <th>Porn Name</th>
    <th>Date of Birth</th>
    <th>Dream Vacation City</th>
    <th>GPA</th>
    <th>Arbitrary Data</th>
</tr>
    </thead>

附件是responsive_table.html程序。

最佳答案

使用 HTML5 属性:

#some-id td:before { content: attr(data-title); }


#some-id td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 1px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
text-align:left;
font-weight: bold;
}

然后:

<tr class="padding">
     <th>
          sth
     </th>
<tr>
<tr>
      <td data-title="sth">

      </td>
</tr>

关于html - CSS使表格自动从thead变成一列标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23726182/

相关文章:

html - Firefox 和 Chrome 浏览器之间的表格问题

javascript - 单击并使用 jquery 选择图像的垂直切片

javascript - 输入不为空时显示按钮 |不工作JS

javascript - 减少选择元素中的下拉宽度

html - @media 查询和常规的 css 交互

javascript - ie8 上的 Jquery 脚本错误

javascript - 如何将 jquery 模板文件保存为每个文件中有多个模板的外部模板文件?

css - 为什么这些元素不重叠?

javascript - jquery/js closest().attr() 返回未定义

javascript - 图像特定区域的可点击链接