Html 使用边距设置跨度之间的距离
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3440209/
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
Set distance between spans using margin
提问by andrii
Here is two spans(in real life a lot of spans) situated at the web page. I would like to set the distance betwwen them. I want to use margin-bottom attribute for this, but I can't see any affect of using it. The spans are still on the previous position. That is wrong. Here is my code:
这是位于网页上的两个跨度(在现实生活中很多跨度)。我想设置它们之间的距离。我想为此使用 margin-bottom 属性,但我看不到使用它的任何影响。跨度仍然在以前的位置。那是错的。这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title></title>
<style type="text/css">
.position, .name{
overflow: hidden;
}
.position{
margin-bottom: 40px;
}
</style>
</head>
<body>
<span class="position">Designer</span><br/>
<span class="name">John Smith</span>
</body>
</html>
回答by Pascal
span
is an inline element, not a block element, and they don't respect (vertical) margin
. You can use padding or make the span display:inline-block;
and then use margins. The latter is now supported in most somewhat newer browsers.
span
是内联元素,而不是块元素,并且它们不尊重 (vertical) margin
。您可以使用填充或制作跨度display:inline-block;
,然后使用边距。大多数较新的浏览器现在都支持后者。
回答by DonkeySticks
I would say line-height is what you are looking for.
我会说 line-height 是你正在寻找的。