Html 如何在跨度元素中应用空间

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

How to apply space in span element

html

提问by Jagadeesh

I have been trying to apply one white space inside the span element, but couldn't able to do it.

我一直试图在 span 元素内应用一个空格,但无法做到。

In my application i have the following two span elements.

在我的应用程序中,我有以下两个 span 元素。

<span style='color:red;margin-right:1.25em'>*</span> 
<span style='color:red;margin-right:1.25em'>&nbsp;</span>

Applied these two spans to different fields to get them in to the same alignment level, but i have the following problem. PFB enter image description here

将这两个跨度应用于不同的领域以使它们处于相同的对齐级别,但我有以下问题。PFB 在此处输入图片说明

is there any thing wrong with the above code

上面的代码有什么问题吗

the first name field should move a bit right for the proper alignment.

为了正确对齐,名字字段应该向右移动一点。

回答by jwchang

margin is applied to blockor inline-blockelements

边距应用于内联块元素

but not inlineelement like

但不像内联元素

spantags

跨度标签

try this

尝试这个

<span style='color:red;margin-right:1.25em; display:inline-block;'>&nbsp;</span>

回答by Jukka K. Korpela

Since spanelements are inline elements by default, horizontal margins are ignored for them by the spec. You can make them inline blocks (supported by most, but not all, browsers), or use padding instead of margin.

由于span默认情况下元素是内联元素,规范会忽略它们的水平边距。您可以将它们设置为内联块(大多数但不是所有浏览器都支持),或者使用填充而不是边距。

This probably won't solve the ultimate problem, as the characters “*” and the no-break space are not of the same width, except by accident. To set up a table of data consisting of form fields and associated labels and explanations, use an HTML table, and then just add a little styling in CSS.

这可能不会解决最终的问题,因为字符“*”和不间断空格的宽度不同,除非是偶然的。要设置由表单字段和相关标签和说明组成的数据表,请使用 HTML 表,然后在 CSS 中添加一些样式。