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/