html - 更改字体样式时如何防止表格上下文调整大小/更改填充?
问题描述
我创建了一个有几行的表。当我单击其中一个时,该行中的文本变为粗体并且颜色发生变化(无关紧要的外部脚本)。问题是当我点击其中任何一个时,整个表格布局会移动少量像素。尝试删除类,刷新并再次添加 - 你会明白我的意思。
我确实尝试阅读了一些关于类似问题的解决方案,但到目前为止没有任何结果。
HTML CODE
<body>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Lastname</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Justin</td>
<td>Kekars</td>
<td>31</td>
</tr>
<tr>
<td>2</td>
<td>Thomas</td>
<td>The tank</td>
<td>18</td>
</tr>
<tr>
<td>3</td>
<td>Jamie</td>
<td>Paul</td>
<td>46</td>
</tr>
<tr class="active-row">
<td>4</td>
<td>Michael</td>
<td>Mouse</td>
<td>21</td>
</tr>
</tbody>
</table>
</body>
CSS CODE
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root{
--green-color: #009879;
}
body{
background-color: #ddd;
}
.table{
border-collapse: collapse;
table-layout: fixed;
margin: 25px 10px;
font-size: 0.9em;
min-width: 400px;
border-radius: 5px 5px 0 0;
overflow: hidden;
box-shadow: 0 0 20px rgba(0,0,0,0.15);
cursor: context-menu;
}
.table thead tr{
background-color: var(--green-color);
color: #ffffff;
text-align: left;
font-weight: bold;
}
.table th,
.table td{
padding: 12px 15px;
}
.table tbody tr {
border-bottom: 1px solid #ddd;
}
.table tbody tr:nth-of-type(even){
background-color: #f3f3f3;
}
.table tbody:last-of-type{
border-bottom: 2px solid var(--green-color);
}
.active-row{
font-weight: bold;
color: var(--green-color);
}
解决方案
推荐阅读
- c# - 如何使用 C# 脚本 (csx) 从函数中获取 Azure 函数名称
- sql - 基于值的请求优先级的并发控制
- node.js - 从 localhost 上的 Node.js 服务器连接到 PostgreSQL 数据库时出错。“关闭 SSL”
- python-3.x - 删除 Tkinter 标题栏和窗口边框?
- reactjs - 无法在 WSL2 上渲染 + 反应
- xcode - 泊坞窗图像内的蒸气“公共”目录未暴露
- java - Android中的每日通知不起作用
- javascript - @react-three/drei 东西不适用于 next.js
- swift - 获取 alamofire 请求以在命令行应用程序中执行
- python - 如何使用 np.where() / np.select() 或 pandas/python 中的一些更好的方法执行计算?