2

While telling someone padding only accepts positive values I realized I can't single out any reasonable technical explanation for it. So I looked it up and this is what I found.

From my point of view, the accepted answer doesn't hold enough water. It's somewhat opinionated and tries to find excuses, rather than reasons for the status-quo (in the sense it's not focused on any problems negative padding values might cause or why browsers would have trouble applying them). I tried to pinpoint it there, but soon realized the question, in current form, won't get me closer to a proper answer. Rather than stalking it, I chose to ask one where I would specifically ask for answers drawing from official and/or credible sources.

What would be so wrong, nonsensical or against core principles of CSS about negative padding values?

Admittedly, this technique is not required often, but when it is, the only way to achieve the effect is by adding an extra wrapper around content, and make use of the wrapper's negative margins. Anyway you look at it, that's sub-par when compared with a potential technique using less markup.

A relatively weak (from my POV) explanation is that padding is defining the relation between content and background. But background limits can be easily attached to other limits of the box-model, using box-sizing. I believe padding ultimately defines a relation between content and border area, and the one between content and background is just resulting from the default relation between border area and background. Why is it we are only allowed to push these border-area limits in one direction but not the other?


Upon digging official documentation, I didn't find any clue on why this decision was made or what was it based upon:

Padding values cannot be negative.

...in CSS Level 1, and

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

...in CSS Level 2 (Revision 1) and in Basic-box model.

Notably, one of the issues discussed in Editor's Draft is entitled: "Issue 23 Allow negative padding?".

Does anyone have any idea if it's still under consideration/debate and what arguments are/were tossed?


Edit, based on comment from @MrLister. Here's what type of answers I'm looking for:

  • either providing some technical reason on why this would be a bad idea and how it would impair other properties/current implementation of box-model, etc...
  • someone who took part in it to step up and say: "Perhaps we rushed it, but this seemed like the proper decision at the time, we didn't think it twice";

Ideally, if the reason(s) why negative padding was not allowed no longer apply, the Spec should change to allow them at some point.

I have to point out I'm not really cut out to be an advocate of causes. In the sense that I know, taken as a hole, my question sounds complain-ish. And that's not what I intended. I'm not really interested in pointing fingers. What I wanted was to know if any show-stoppers are in place, to get other people to consider it (maybe they see something I'm missing) and, if the initial reason(s) no longer apply, to (hopefully) get the issue considered by whoever is in charge of where CSS standards are going today.
I believe negative padding values would be a good addition to the tools of any modern web developer and so far I don't see any major downside to it.

tao
  • 82,996
  • 16
  • 114
  • 150
  • 2
    If it were under active consideration, I'd expect there to be threads about it on the www-style mailing list and there aren't. – Alohci Jan 09 '18 at 01:40
  • Negative padding pretty much means the content would overflow the container, which is a great recipe for broken stuff. Could you elaborate a example on which having negative padding would be practical? – Facundo Corradini Jan 09 '18 at 03:19
  • @FacundoCorradini, you just described any case where a child overflows its parent as *"a great recipe for broken stuff"*. By your logic, we should take sharp knives from butchers, to prevent them from cutting their fingers. – tao Jan 09 '18 at 05:13
  • No need to go there man... Just wanted to know what is that you're after, trying to understand a possible realistic scenario on which having negative padding would be useful – Facundo Corradini Jan 09 '18 at 05:15
  • @Facundo, you probably misunderstood my question. I'm not here because I have a client who asked me to make a webpage and I don't know how to do it. I believe in web anything is possible. And in most cases, it is. When it's not, I'm doing it wrong. But I want to understand why people who made the standard thought pushing the border area away from content is good idea and should be possible and pulling it towards content is a bad idea and should not be possible. As in, why do I have to add an extra child with negative margin to achieve this effect while I could simply add in a negative padding. – tao Jan 09 '18 at 05:22
  • @Facundo, a practical example is one with wide border images where content needs to overlap border images. Using `background-image` for the effect is not feasible, because the container size is determined by content length. – tao Jan 09 '18 at 05:41
  • I understood, I just simply couldn't find an example that we weren't able to achieve with other methods. But getting rid of wrappers is always welcomed. ---- I believe the problem is that paddings are defined as the area between the content and the border, so a negative padding would make the actual box smaller towards the center, effectively clipping your content, or making a rendering issue for the browser. Boxy spec is boxy. Going back to your example, maybe some elaborate stacking multiple brackgrounds... or inset box shadows would do the trick – Facundo Corradini Jan 09 '18 at 06:03
  • Or some combination of background-origin, background-clip, background-size:90%, background-position https://codepen.io/facundocorradini/pen/wpyBeN – Facundo Corradini Jan 09 '18 at 06:25
  • Not exactly, @MrLister. Their width would be the exact size of `border-image` and would be positive. And one would use negative padding values to set how much the positive width borders would overlap with the content. Negative padding makes sense to me, being a distance. Negative width border doesn't so much. If the width of borders would be negative, how would you paint the border? Inside out? But the main point here is width of border and distance from content to border are completely different settings. – tao Jan 09 '18 at 09:15
  • Having read all the answers on the linked question now, I believe that no answer whatsoever will satisfy you. Any answer will be considered an excuse, rather than a reason, for the current situation. – Mr Lister Jan 09 '18 at 09:15
  • @MrLister: I'll accept any answer that either: **a)** presents a scenario where negative padding values would produce unwanted, unpredictable or erratic browser behavior (at least in theory) or **b)** provides some sort of explanation on who, how and why decided this, even if it was for the wrong reason, for no reason or if the reason no longer applies. If coming from anyone implicated in the design process of this attribute, a simple *"Someone (can't remember who) said negative padding doesn't make sense and we all agreed"* will suffice. – tao Jan 09 '18 at 09:32
  • 2
    The "who" we can largely identify. Negative paddings were disallowed in CSS Level 1, which was overwhelmingly the work of Håkon Wium Lie – Alohci Jan 09 '18 at 22:45
  • Thank you @Alohci, I welcome your help. I didn't mean to point fingers. My goal was to raise awareness around this and, hopefully, to get it reconsidered, especially since it looks like there's no other reason behind this decision other than it's a marginal design case. I've outlined my intent in a new *last* paragraph of the *question* (if I can still call it that). :) Best regards. – tao Jan 09 '18 at 23:15
  • 2
    Does this mean you just want to hear it from the horse's mouth if possible? If so there's nothing stopping you from bringing it up again on www-style - the last time someone did that was [15 years ago](https://lists.w3.org/Archives/Public/www-style/2003May/0057.html) apparently... – BoltClock Jun 28 '18 at 18:56
  • @Bolt, good idea. I might, but not in the next 2 weeks. I'm on a break. – tao Jun 28 '18 at 21:02

0 Answers0