html - 给 `<span>` 负垂直边距

标签 html css margin

为什么不能 <span>有一个负的垂直边距或填充?

如果我将它设置为 display: block , 它仍然不起作用。

最佳答案

来自 CSS 2.1 规范:

8.3 Margin properties: 'margin-top', 'margin-right', 'margin-bottom', 'margin-left', and 'margin'

Margin properties specify the width of the margin area of a box. The 'margin' shorthand property sets the margin for all four sides while the other margin properties only set their respective side. These properties apply to all elements, but vertical margins will not have any effect on non-replaced inline elements.

<span>默认情况下,是一个不可替换的内联元素。

还有

8.4 Padding properties: 'padding-top', 'padding-right', 'padding-bottom', 'padding-left', and 'padding'

...

Unlike margin properties, values for padding values cannot be negative.

关于html - 给 `<span>` 负垂直边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13537255/

相关文章:

css - jquery 移动按钮的自定义透明 css 样式

html - 如果有子列表css,如何水平对齐列表

html - 由于位置限制而出现空白?

java - 通过springboot和thymeleaf列出从数据库到html页面的对象

java - 不同的 JEditorPanes 显示 html 内容,使用相同的 css 规则

html - 负边距导致内容在缩放期间移动

html - CSS float ,中间有相等的间距

CSS:我可以通过 margin: 0 0 0 auto 右对齐一个元素吗?

javascript - 添加非居中文本会移动居中元素

html - XSLT:转换为 HTML 时删除空格