[英]How to expand flex container outside parent element
I need to relatively position some flex container, so I set it parent display relative and flex itself - absolute.我需要相对定位一些 flex 容器,所以我将它设置为父显示相对和 flex 本身 - 绝对。 But the problem is that flex width does not expands outside its relative parent.
但问题是 flex 宽度不会扩展到其相对父级之外。 How to fix this?
如何解决这个问题?
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet" /> <div class="w-1/3 bg-blue-500 mx-auto my-5 relative p-4"> <div class="absolute flex flex-wrap border border-red p-4"> <div class="border-b w-1/2">content super long</div> <div class="border-b w-1/2">content super long</div> <div class="w-1/2">content super long</div> <div class="w-1/2">content super long content</div> </div> </div>
There is enough space for flex container to display its content with no line wraps. flex 容器有足够的空间来显示其内容而无需换行。 But it does not so.
但事实并非如此。
I need following result:我需要以下结果:
You can achieve that by changing position
property of parent element to static
, In addition to adding another container with relative position
.您可以通过将父元素的
position
属性更改为static
来实现这一点,此外还可以添加另一个具有relative position
容器。
Example:例子:
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet"> <div class="w-1/3 bg-blue-500 mx-auto my-5 relative p-4" style="position:static"> <div class="container" style="position:relative"> <div style="width:500px;" class="absolute flex flex-wrap border border-red p-4"> <div class="border-b w-1/2">content super long</div> <div class="border-b w-1/2">content super long</div> <div class="w-1/2">content super long</div> <div class="w-1/2">content super long content</div> </div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.