有没有一种优雅的方式来制作/生成空间而不是 &nbsp?

发布于 2024-08-12 18:00:41 字数 25 浏览 4 评论 0原文

我需要在 HTML 文件中生成空格。

I need to generate spaces in a HTML file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

梦幻之岛 2024-08-19 18:00:41

使用  

 标记。 
 标记保留所有空格、制表符和换行符。

编辑
关于您对其使用的评论,对于填充,您可能需要查看 css padding

Use either   or <pre> tags. The <pre> tag preserves all spaces, tabs and newlines.

EDIT
Regarding your comment about its use, for padding, you may want to look at css padding

你对谁都笑 2024-08-19 18:00:41

这一切都取决于上下文,您可以使用字母间距、单词间距或例如周围跨度的填充。

如果没有更多信息,就不可能给出好的建议。

编辑:如果它用于文本/单词之间,我会选择单词间距,也许还有字母间距。

It all depends on the context, you can use letter-spacing, word-spacing or for example padding for surrounding span's.

Without more information it´s impossible to give a good advice.

Edit: if it´s for use in texts / in between words, I´d go for the word-spacing and perhaps letter-spacing.

柠檬 2024-08-19 18:00:41

我几乎从不使用  

marginpadding 属性对于间距和
效果很好> 用于换行符。 (我也不经常使用
。)

I hardly ever use  

margin and padding properties work well for spacing and <br /> for newlines. (I don't use <br /> too frequently either.)

ゞ花落谁相伴 2024-08-19 18:00:41

 是一个不间断的空格。或者,我想您可以使用
(那里是 XHTML)标记来生成新行。

  is a non-breaking space. Alternatively I guess you could use a <br /> (XHTML there) tag just to generate a new line.

初见终念 2024-08-19 18:00:41

我使用带有 css 类的跨度。
我有几个类,如 spacer_1、spacer_2、spacer_3 等。
我使用不同的水平填充,像这样

.spacer_1
{
    padding:0px 5px;
}

使用这个垫片,你可以使用以下

<span class="spacer_1" /> /*this will generate half the gap*/
<span class="spacer_1"></span>
<span class="spacer_1">|</span>

i use a span with css classes.
i have several class like spacer_1, spacer_2, spacer_3, etc..
i use different horizontal padding like this

.spacer_1
{
    padding:0px 5px;
}

to use this spacer you can use the following

<span class="spacer_1" /> /*this will generate half the gap*/
<span class="spacer_1"></span>
<span class="spacer_1">|</span>
原谅过去的我 2024-08-19 18:00:41

就这样做:

/* in your css code:  */ 
pre
{
  display:inline;   
}
<!-- and then, in your HTML markup: -->

<pre>    this text comes after 4 spaces.</pre>
<span> continue the line with other element without braking </span>

just do:

/* in your css code:  */ 
pre
{
  display:inline;   
}
<!-- and then, in your HTML markup: -->

<pre>    this text comes after 4 spaces.</pre>
<span> continue the line with other element without braking </span>
我家小可爱 2024-08-19 18:00:41

雅各比是对的。但我有一些不同的东西:

<head>

<style type="text/css">
    .left-space { margin-left: 10px; }
</style>

</head>

<body>

<div>
   <p>This is a test line.<span class="left-space">This is a line with space before it.</span></p>
</div>

</body>

顺便说一句,您应该用   替换   以符合 XHTML。

Yacoby is right. But i have something different:

<head>

<style type="text/css">
    .left-space { margin-left: 10px; }
</style>

</head>

<body>

<div>
   <p>This is a test line.<span class="left-space">This is a line with space before it.</span></p>
</div>

</body>

And by the way you should replace   with   to conform to XHTML.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文