css - 在其标题的末尾位置对齐表格内容
解决方案
您将需要 3 列,将 3 tds 或 1 td + 伪元素转换为 table-cell 。
对于 flex 或 grid 布局,您还需要 3 列开始。
前任:
table {
width: 100%;
border: dashed;
border-collapse: collapse;
background: linear-gradient(to left, transparent 50%, rgba(0, 0, 0, 0.2) 50%)
}
tr:not(:first-of-type):not(:last-of-type) {
border: dashed
}
tr:before,
tr:after {
content: '';
display: table-cell;
width: 50%
}
td {
padding: 0.45em;
width: 0;
white-space: nowrap;
text-align: right;
background: linear-gradient(to right, transparent 50%, rgba(100, 0, 0, 0.2) 50%)
}
/* ==== flex , not use ===*/
section {
display: flex;
border: dashed;
position: relative;
background: linear-gradient(to left, transparent 50%, rgba(0, 0, 0, 0.2) 50%)
}
section:before,
section:after {
content: "";
flex: 1;
}
p:not(:first-of-type):not(:last-of-type):before {
content: '';
position: absolute;
width: 100%;
left: 0;
bottom: 32.5%;
top: 32.5%;
border-top: dashed;
border-bottom: dashed
}
p {
margin: 0;
padding: 0.5em;
white-space: nowrap;
text-align: right;
background: linear-gradient(to right, transparent 50%, rgba(100, 0, 0, 0.2) 50%)
}
/*===== grid ======*/
body>div {
display: grid;
grid-template-columns: 1fr auto 1fr;
border: dashed;
background: linear-gradient(to left, transparent 50%, rgba(0, 0, 0, 0.2) 50%);
position: relative;
}
p {
grid-column: 2;
margin: 0;
padding: 0.5em;
white-space: nowrap;
text-align: right;
background: linear-gradient(to right, transparent 50%, rgba(100, 0, 0, 0.2) 50%)
}
<table>
<caption><code>Table-layout</code></caption>
<tr>
<td>column name</td>
</tr>
<tr>
<td>column </td>
</tr>
<tr>
<td>name</td>
</tr>
</table>
<code>flex</code>, too verbose to be useful
<section>
<div>
<p>column name</p>
<p>column </p>
<p> name </p>
</div>
</section>
<code>grid</code>, efficient enough.
<div>
<p>column name</p>
<p>column </p>
<p> name </p>
</div>
推荐阅读
- ios - 如何处理 Firestore 查询结果以供以后使用
- css - safari 不垂直填充网格自动流:列
- javascript - addEventListener scroll Uncaught TypeError: element.getBoundingClientRect 不是函数
- redisearch - 在redisearch中搜索时我们可以指定不同的字段权重吗?
- java - 在eclipse中将现有的maven项目添加到Maven多模块项目中
- c# - Specflow 并行执行 AfterFeature 的替代方案?
- image - 使用 Perl 导入图像
- python - 在 Pandas 中使用 groupby 时检查某些列的值
- asp.net - 使用 SSRS 在网页中显示报告
- c++ - 与普通变量相比,仅读取原子变量是否有任何性能差异?