When trying to implement support for background-position-block/background-position-inline and the new logical keywords added to <position> in CSS Values 5, I ran into an issue with the fact that background-position (and background) operate on lists of backgrounds.
To explain the issue, let's start with an existing example where you have the following usage:
<div id="test1" style="background-position: left bottom, right top;">...</div>
In this example, the following assertions hold:
assert(document.getElementById("test1").style.backgroundPositionX == "left, right");
assert(document.getElementById("test1").style.backgroundPositionY == "bottom, top");
Simple. When processing the shorthand, the parser split each background-position pair into an x and y component and created lists with them.
Now, consider a case using the new logical keywords along with the old physical keywords:
<div id="test2" style="background-position: left bottom, block-start inline-end;">...</div>
What should the following assertions be?
assert(document.getElementById("test2").style.backgroundPositionX == ???);
assert(document.getElementById("test2").style.backgroundPositionY == ???);
assert(document.getElementById("test2").style.backgroundPositionBlock == ???);
assert(document.getElementById("test2").style.backgroundPositionInline == ???);
Internally in the engine, we would probably be modeling this as with some placeholder value that tells the style building to not do anything for that specific value:
backgroundPositionX == [ left, <placeholder> ]
backgroundPositionY == [ bottom, <placeholder> ]
backgroundPositionBlock == [ <placeholder>, block-start ]
backgroundPositionInline == [ <placeholder>, inline-end ]
But its not clear how that would serialize.
Two ideas, both from @fantasai, are:
- Allow lists to have empty values that take the place of the placeholder:
assert(document.getElementById("test2").style.backgroundPositionX == "left, ");
assert(document.getElementById("test2").style.backgroundPositionY == "bottom, ");
assert(document.getElementById("test2").style.backgroundPositionBlock == ", block-start");
assert(document.getElementById("test2").style.backgroundPositionInline == ", inline-end");
- Add an explicit
defer keyword for the same purpose:
assert(document.getElementById("test2").style.backgroundPositionX == "left, defer");
assert(document.getElementById("test2").style.backgroundPositionY == "bottom, defer");
assert(document.getElementById("test2").style.backgroundPositionBlock == "defer, block-start");
assert(document.getElementById("test2").style.backgroundPositionInline == "defer, inline-end");
I prefer the explicitness of the defer keyword.
When trying to implement support for
background-position-block/background-position-inlineand the new logical keywords added to<position>in CSS Values 5, I ran into an issue with the fact thatbackground-position(andbackground) operate on lists of backgrounds.To explain the issue, let's start with an existing example where you have the following usage:
In this example, the following assertions hold:
Simple. When processing the shorthand, the parser split each
background-positionpair into anxandycomponent and created lists with them.Now, consider a case using the new logical keywords along with the old physical keywords:
What should the following assertions be?
Internally in the engine, we would probably be modeling this as with some placeholder value that tells the style building to not do anything for that specific value:
But its not clear how that would serialize.
Two ideas, both from @fantasai, are:
deferkeyword for the same purpose:I prefer the explicitness of the
deferkeyword.