Html 如何在两个跨度元素之间添加间距

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

How to add spacing between two span elements

csshtml

提问by Ankur

I have two span elements. I want them to sit side-by-side and contain some text. Is this possible? If so what am I doing wrong?

我有两个跨度元素。我希望他们并排坐着并包含一些文字。这可能吗?如果是这样,我做错了什么?


.added-box{
 background-color:#06C;
 padding:8px;
 margin:8px;
}

.edited-box{
 background-color:#093;
 padding:8px;
 margin:8px;

}

And the page code is:

页面代码是:

<p align="right">
   <span class="edited-box">sfds<span>
   <span class="added-box">sfds<span>
</p>

Edit: What I am hoping to get is a box, somewhat like the one on this page which has my name, time I asked the question and my points. I don't mind how I get it, but css is preferred, it looks like StackOverflow is using a table. Is this the only way to do this?

编辑:我希望得到的是一个盒子,有点像这个页面上有我的名字、我提出问题的时间和我的观点的盒子。我不介意我是如何得到它的,但是 css 是首选,看起来 StackOverflow 正在使用表格。这是唯一的方法吗?

回答by irishbuzz

You have two typos in your HTML where you are failing to close the <span>tags with </span>. It should be:

您的 HTML 中有两个拼写错误,您无法<span>使用</span>. 它应该是:

<p align="right">
  <span class="edited-box">sfds</span>
  <span class="added-box">sfds</span>
</p>

This typo is causing your edited-boxclass to wrap everything and therefore the CSS is breaking.

这个错字导致你的edited-box班级包装了所有东西,因此 CSS 被破坏了。

回答by Aman

Use &nbsp;for space between spans.

使用&nbsp;的跨度之间的空间。