表格单元格中的 HTML/css 文本不缩进

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10833556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:46:11  来源:igfitidea点击:

HTML/css text in table cell not indenting

htmlcsshtml-table

提问by user1260310

A simple question but large impact on appearance.

一个简单的问题,但对外观的影响很大。

I want text indented from cell border and have tried style=text-indent: 4px(not formatted so it displays properly here) but while the first line is indented, the lines after the <br>tags are not indenting. Please help. I need to use div because of some Javascript. Here is flawed code:

我想要从单元格边框缩进的文本并尝试过 style=text-indent: 4px(未格式化,因此在此处正确显示)但是当第一行缩进时,<br>标签后面的行没有缩进。请帮忙。由于某些 Javascript,我需要使用 div。这是有缺陷的代码:

<td>
   <div id="navbar" style="text-indent:4px"><b>View by:</b><br>
      <a href="search.php?cat=pop">Popular</a><br>
      <a href="search.php?cat=trend">Trending</a><br>
   </div>
</td>

回答by Quentin

text-indentis only supposed to touch the first line. Use margin(or margin-leftor paddingor etc) if you want to adjust the entire block.

text-indent应该只接触第一行。如果要调整整个块,请使用margin(or margin-leftor paddingor etc)。

回答by richardev

Try adding paddding to element, that holds your text you want to indent.

尝试向元素添加填充,以保存要缩进的文本。

   <td style="padding:5px;">text</td>