在下面的示例中,我希望定位具有id
然而,正如你所看到的那样,
有人能解释一下涉及这种行为的神奇力量是什么,以及我如何指定
在第三个示例中,我添加了一些不太可压缩的文本,这肯定会改善情况。不知何故,也是 flex 容器的 flex 项比常规块元素更可压缩。
child
的元素,使其右上角与具有id container
的元素的右上角相匹配。换句话说,child
应该突出到 container
的左侧和底部,并使其右边缘和顶部与 container
对齐。然而,正如你所看到的那样,
child
被压缩以匹配 container
的宽度。但并非完全如此——在第二个示例中,很明显,child
被压缩到某个限制后,开始按照所需的方式行为(即相对于 container
向左移动)。有人能解释一下涉及这种行为的神奇力量是什么,以及我如何指定
child
不应在其内在大小以下被压缩吗?在第三个示例中,我添加了一些不太可压缩的文本,这肯定会改善情况。不知何故,也是 flex 容器的 flex 项比常规块元素更可压缩。
<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>
overflow
只能发生在文本方向上(否则就不是溢出)。https://dev59.com/Hpnga4cB1Zd3GeqPYnGF#38830775 - Michael Benjamin