html - 当 td 有文本时如何最小化 td 高度?

标签 html css

我需要的是一个 14px 的文本,在 16px td(高度)内。 当我尝试用一​​个空的 td 来做时,这是可行的,但是当我输入一些文本时,td 会自动采用 20px 的高度。这留下了我不想要的 2px 顶部和底部边距。

html:

<table>
<tr><td>09:00 - 12:00</td><td>09:00 - 12:00</td></tr>
<tr><td>09:00 - 12:00</td><td>09:00 - 12:00</td></tr>
</table>

CSS

table{
    border-collapse: collapse;
}
td{
    background-color: #5589DC;
    color:white;
    font-family: Calibri;
    font-size: 14px;
    border: 1px solid black;
    height: 16px;
}

这是结果(20px td 高度):

enter image description here

但这就是我想要的(16px td 高度(用油漆修改)):

enter image description here

有什么想法吗?

最佳答案

将 height:16px 改为 line-height:13px,这样会减少 TD 内的空间。

关于html - 当 td 有文本时如何最小化 td 高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39985918/

相关文章:

javascript - Bootstrap Grid 以错误的方式折叠 : elements lie on top of other elements

html - 下拉悬停时 Firefox 中的额外像素

html - 使 flex 元素在一行中具有相等的宽度

javascript - “调整大小”窗口事件似乎只在垂直调整大小时触发

html - 在页面重定向上保持按钮状态

css - float div 之间的均匀间距

javascript - ng-switch 在某些情况下不起作用

html - 顶部有不透明图案的 css 背景渐变

html - PHP 代码和 html 未在网页中呈现

javascript - JQuery 事件导致页面重新加载。怎么修?