In example below I want to position element with id child
, so it's right-top corner matches right-top corner of element with id container
. In other words, it's desired for child
to stick out to the left and to the bottom of container
and have its right and top edges aligned with container
.
However, as you can see child
is compressed to match container
width. But not completely - in second example it's clear that child
is compressed up to some limit and then begins to behave as desired (i.e. move to the left relative to the container
).
Can somebody explain what magic forces are involved in such behavior and how I can specify that child
shouldn't compress below its intrinsic size?
In third example I add some less compressible text, which definitely improves the situation. Somehow flex item that are also flex containers are much more compressible than regular block elements.
<div id="container" style="position: relative; width: 100px; height: 100px; left: 50px; border: 1px solid red">
<div id="child" style="position: absolute; display:flex; flex-direction: column; right: 0px; border: 1px solid blue">
<div style="
display:flex">
<div style="flex: 1 0 auto">Long text 1</div>
<div style="flex: 0 0 auto">Long text 2</div>
</div>
<div style="display:flex">
<div style="flex: 1 0 auto">Long text 1</div>
<div style="flex: 0 0 auto">Long text 2</div>
</div>
</div>
</div>
<hr>
<div id="container" style="position: relative; width: 50px; height: 100px; left: 50px; border: 1px solid red">
<div id="child" style="position: absolute; display:flex; flex-direction: column; right: 0px; border: 1px solid blue">
<div style="
display:flex">
<div style="flex: 1 0 auto">Long text 1</div>
<div style="flex: 0 0 auto">Long text 2</div>
</div>
<div style="display:flex">
<div style="flex: 1 0 auto">Long text 1</div>
<div style="flex: 0 0 auto">Long text 2</div>
</div>
</div>
</div>
<hr>
<div id="container" style="position: relative; width: 50px; height: 100px; left: 50px; border: 1px solid red">
<div id="child" style="position: absolute; display:flex; flex-direction: column; right: 0px; border: 1px solid blue">
<div style="white-space: nowrap;">This is just ridiculous</div>
<div style="
display:flex">
<div style="flex: 1 0 auto">Long text 1</div>
<div style="flex: 0 0 auto">Long text 2</div>
</div>
<div style="display:flex">
<div style="flex: 1 0 auto">Long text 1</div>
<div style="flex: 0 0 auto">Long text 2</div>
</div>
</div>
</div>