html - 调整表格单元格以适合文本

标签 html css

如何使表格单元格与其中的文本一样小?我也尝试设置边距、填充和空白,但它们都不起作用:

HTML

<table class='header_left'>
    <tr>
        <td><a href='/index.php' class='title1'>somewebsite.com</a></td>
    </tr>
    <tr>
        <td class='vonal'><a href='/index.php' class='title2'>Check something and do it faster than your competitors</a></td>
    </tr>
</table>

CSS

table.header_left {
    float:left;
    text-align:left;
    margin:0;
    padding:0;
    border-collapse: collapse;
}

table.header_left a.title1 {
    color: #e6e8ea;
    font-size: 39px;
    text-decoration:none;
    margin:0;
    padding:0;
}
table.header_left a.title2 {
    color: #c1c2c4;
    font-size: 14px;
    text-decoration:none;
    margin:0;
}
table.header_left td.vonal {
    border-bottom:1px solid #c1c2c4;
    text-decoration:none;
}
table.header_left td {
    border:1px solid;
    white-space: nowrap;
    padding:0;
    margin:0;
}

http://jsfiddle.net/RZHPD/

如您所见,文本“somewebsite.com”周围有填充。我希望将其删除。

谢谢

最佳答案

这是因为文本/字体的默认填充。你可以尝试在你的 css 中添加:

table.header_left a.title1 { 
   line-height:15px; 
   float: left;
}

关于html - 调整表格单元格以适合文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20653683/

相关文章:

javascript - 如何在每秒点击一次时反转动画?

javascript - HTML 表单不使用 appendChild 提交

jquery - 单击时从中心向左动画 div

java - 我怎样才能从这个表中在jsp中做出正确的问答?

javascript - 直接移动带有范围的元素 -javascript

html - 在导航上有一个仍然与导航一起工作的偏移链接

html - 如何将 div/占位符放入 bootstrap 网格

css - 在不使用 z-index 的情况下将一个 div 层叠在另一个之上时观察到的意外结果

css - 如何用图标覆盖图像

html - 如何让 div 随内容增长而不覆盖其他内容