Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Giving a `<span>` a negative vertical margin

Tags:

html

css

margin

Why can't a <span> have a negative vertical margin or padding?

If I set it to display: block, it still doesn't work.

like image 417
Don P Avatar asked Oct 18 '25 11:10

Don P


1 Answers

From the CSS 2.1 spec:

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> is, by default, a non-replaced inline element.

Also

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

...

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

like image 108
Alohci Avatar answered Oct 21 '25 03:10

Alohci



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!