Javascript 在 html 中插入一个制表符或空格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27402840/
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-23 00:06:37  来源:igfitidea点击:

Insert a tab or spaces in html

javascripthtmlcss

提问by President Camacho

I'm new to html and I got this piece of code:

我是 html 的新手,我得到了这段代码:

@{ 
    ViewBag.Title = "Index";
}

<!DOCTYPE html>

<html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>View1</title>
        <script src="~/Scripts/jquery-1.9.1.min.js"></script>
        <script src="~/Scripts/bootstrap.min.js"></script>
        <link href="~/Content/bootstrap-theme.min.css" rel="stylesheet" />
        <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
    </head>
    <body>  
        <table>    
            @foreach (var item in Model.Data)
            { 
                <tr>
                    <td><a [email protected][item.Key]>@item.Key</a></td>
                    <td>@item.Value</td>
                </tr>                        
            }
        </table>
    </body>
</html>

I want to add a tab or spaces between: <td><a [email protected][item.Key]>@item.Key</a></td>and <td>@item.Value</td>how do I do that?

我想添加一个标签或之间的空间:<td><a [email protected][item.Key]>@item.Key</a></td><td>@item.Value</td>我该怎么做呢?

I guess adding css is the best way but I don't understand how to use it.

我想添加 css 是最好的方法,但我不明白如何使用它。

采纳答案by JLRishe

You can add padding to your tdwith CSS:

您可以td使用 CSS向您添加填充:

td {
  padding-right: 30px;
}
<table>
  <tr>
    <td><a href="#">Hello</a></td>
    <td>Goodbye</td>
  </tr>
  <tr>
    <td><a href="#">Hola</a></td>
    <td>Adios</td>
  </tr>
</table>

or give them a fixed width:

或者给他们一个固定的宽度:

td {
  min-width: 200px;
}
<table>
  <tr>
    <td><a href="#">Hello</a></td>
    <td>Goodbye</td>
  </tr>
  <tr>
    <td><a href="#">Hola</a></td>
    <td>Adios</td>
  </tr>
</table>

回答by Deblaton Jean-Philippe

`&nbsp;` is a space
`&#09;` is a tab

Just insert them where you want

只需将它们插入您想要的位置

For the CSS, you should use the padding property, there are plenty of tutorials on the web, and samples

对于 CSS,你应该使用 padding 属性,网上有很多教程和示例

回答by FDM

You mean visual whitespace?

你的意思是视觉空白?

In that case, check this linkfor:

在这种情况下,请查看此链接以了解:

  • How to add styles for a table
  • The paragraph Table Padding specifically.
  • 如何为表格添加样式
  • 段落Table Padding 专门。

Basic CSS isn't that hard.

基本的 CSS 并不难。

回答by Djoezz

<table style="border-spacing: 10px;">

Or in a CSS block somewhere:

或者在某个 CSS 块中:

table {
  border-spacing: 10px;
}

Source : Add space between cells (td) using css

来源:使用 css 在单元格 (td) 之间添加空格