简体   繁体   English

柔性包装盒,在另一个柔性包装盒内包裹

[英]Flex box with wrap inside another Flex box

I have a vertical title layout where the left is a content container, and the right is a title container with a vertical title. 我有一个垂直标题布局,其中左边是内容容器,右边是带有垂直标题的标题容器。 And I want the vertical title to wrap to the next vertical line when title is long. 我想在标题较长时将垂直标题换行到下一个垂直行。

I thought I could achieve this with flex box, but the result is wrong. 我以为我可以用flex box做到这一点,但是结果是错误的。 Code snippet below: 下面的代码段:

 .flex{ display: flex; background-color: red; width: 100%; height: 400px; justify-content: flex-end; } .ctt{ background-color: yellow; } h3{ max-height: 80%; display: flex; flex-direction: column; flex-wrap: wrap; background:blue; align-self: flex-end; } h3 > span{ color: white; display: block; white-space: pre; } 
 <div class="flex"> <div class="ctt"> some content </div> <h3 class="ttl"> <span>A</span> <span> </span> <span>V</span> <span>e</span> <span>r</span> <span>y</span> <span> </span> <span>V</span> <span>e</span> <span>r</span> <span>y</span> <span> </span> <span>L</span> <span>o</span> <span>n</span> <span>g</span> <span> </span> <span>T</span> <span>i</span> <span>t</span> <span>l</span> <span>e</span> </h3> </div> 

As you can see when running the code snippet, the wrap did happen, but you cannot see it. 如您所见,在运行代码片段时,确实发生了换行,但是您看不到它。 I need the title flex item (h3) to expand when a wrap happens so you can see the rest of the title. 当发生换行时,我需要标题弹性项目(h3)进行扩展,以便可以看到标题的其余部分。

Also, testing in Chrome, the title doesn't even wrap. 此外,在Chrome中进行测试时,标题甚至都不会自动换行。 But I think this is Chrome's problem, not the code's problem. 但是我认为这是Chrome的问题,而不是代码的问题。

I don't mind using methods other than flex box, as long as I get the desired result. 我不介意使用flex box以外的方法,只要我能得到期望的结果即可。

Some more info about the layout: 有关布局的更多信息:
the title should be 80% tall of its container. 标题应该是容器高度的80%。
It should be aligned to the bottom. 它应该与底部对齐。
It should be aligned to the right. 它应该右对齐。
It should wrap to next vertical line (at the right) when 80% can no longer accommodate it. 当80%的地方无法容纳它时,它应该绕到下一条垂直线(在右侧)。
When this wrap happens, obviously the width would grow, and content (the yellow box) should be pushed to the left. 发生这种缠绕时,宽度显然会增加,并且内容(黄色框)应向左推。

I feel this is achievable with css, so avoid javascript if possible. 我觉得这可以通过CSS实现,因此请尽可能避免使用JavaScript。

Kind regards. 亲切的问候。


Edit with diagram: 用图编辑:

我的代码目前正在做什么

我想做的事

I find myself very bad at explaining things. 我发现自己很不擅长解释事情。 Hopefully these 2 diagrams help. 希望这两张图对您有所帮助。 I hope. 我希望。

Anyway, the first diagram is the result I get from Firefox, Chrome does not even wrap the text. 无论如何,第一个图表是我从Firefox获得的结果,Chrome甚至没有包装文字。

Diagram 2 is the result I'm looking for. 图2是我正在寻找的结果。 So far the wrapping is achieved with flex-wrap, but it does not push out the container when this wrapping happens. 到目前为止,可以通过flex-wrap进行包装,但是在发生这种包装时,它不会将容器推出。

.flex{height: auto;}

要么

h3{align-self: auto;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM