简体   繁体   English

在嵌套的flexbox容器中缩小包含图像的flexbox

[英]Shrink a flexbox containing images inside a nested flexbox container

I try to ajust some dynamic content so it fit onto label to be printed. 我尝试调整一些动态内容,使其适合要打印的标签。

The label has a row (.symbolContainer) that can contain 0 or more images. 标签的一行(.symbolContainer)可以包含0个或更多图像。 The objective is to shrink that .symbolContainer and those images if the content of .text box need more spaces. 目的是如果.text框的内容需要更多空间,则缩小该.symbolContainer和那些图像。

EDIT: The row of images should not wrap, but shrink from 75px to a minimum of 25px. 编辑:图像行不应该换行,而是从75px缩小到最小25px。

Seem to me that flexbox is the way to go, and it ended up with 3 levels of nested flexbox, but the images inside the .symbolContainer won't shrink. 在我看来,flexbox是必经之路,它最终有3个级别的嵌套flexbox,但是.symbolContainer中的图像不会缩小。

Content of .text div can overflow the .body div, but I will adjust the font-size with javascript after. .text div的内容可能会使.body div溢出,但是之后我将使用javascript调整字体大小。

It is possible to acheive this with flexbox or other tricks? 可以通过flexbox或其他技巧来达到目的吗?

Here is what I have done so far. 到目前为止,这是我所做的。 Comment in CSS is what I wanted to do. 我想在CSS中进行注释。

 .container { width: 3.5in; height: 5in; border: 1px solid black; border-radius: 6px; display: flex; flex-direction: column; } .title { font-weight: bolder; font-size: 24px; text-align: center; } .body { background-color: #aad9fa; flex: 1; overflow: hidden; display: flex; flex-direction: column; } .symbolContainer { display: flex; justify-content: center; background-color: #c1f1bf; flex: 0 1 75px; /* Height is 75px but shrink if need to */ /* No minimum height because can be empty */ } .symbolContainer>img { flex: 0 1 75px; /* Size start at 75 px then shrink */ min-width: 25px; /* but don't shrink pass 25px */ align-self: flex-start; } .text { font-size: 22px; flex: 1; /* Take maximum possible space */ } .footer { text-align: center; height: 30px; background-color: green; } 
 <div class='container'> <div class='title'> A title that can be multiline because of his variable length </div> <div class='body'> <div class='symbolContainer'> <img src="https://simdut.claurendeau.qc.ca/public/img/vector/flamme.svg"> <img src="https://simdut.claurendeau.qc.ca/public/img/vector/nocif.svg"> </div> <div class="text"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam bibendum risus ex, nec gravida augue iaculis vel. Nam malesuada vitae libero ac tempus. Aenean et ipsum ac justo malesuada venenatis. Proin consequat tellus et varius mattis. Vestibulum cursus dui in tincidunt pellentesque. Nullam feugiat lacus sem, et dapibus sapien maximus eu. </p> <p>Vivamus ullamcorper odio ex, sed rhoncus tellus sagittis eu. Proin egestas erat metus, sed congue dolor efficitur ac. Fusce ultrices quis urna vel tristique. Ut fermentum ipsum tellus, vel accumsan dui malesuada nec. Vivamus aliquam justo vel tortor luctus, non venenatis lectus sagittis. Morbi feugiat sem nec elit varius ultricies.</p> </div> </div> <div class='footer'> This is the footer. Can be fixed height </div> </div> 

You don't need those layers for the Flex Containers in order to do the images responsive. 您不需要Flex容器的那些层即可响应图像。

Symbol Container should be: 符号容​​器应为:

.symbolContainer{
 min-width: 0; /* resize as what you want */
 margin: 5px; /* resize as what you want */
}

img {
width: 450px; /* resize as what you want */
max-width: 100%; /* resize as what you want */ 
max-height: 450px; /* resize as what you want */
}

.imgContainer{
 display: flex;
 justify-content: center;
 flex-wrap: wrap;
}

Now the html should change to: 现在,html应该更改为:

 <div class='body'>
   <div class='imgContainer'>
      <div class='symbolContainer'>
        <img src="https://simdut.claurendeau.qc.ca/public/img/vector/flamme.svg">
        <img src="https://simdut.claurendeau.qc.ca/public/img/vector/nocif.svg">
      </div>
   </div>
...

That should do what you want. 那应该做你想要的。 Be aware to resize to what you want. 请注意调整大小以适合您的需求。

Hope it helps! 希望能帮助到你!

pd. 页码 It's based on this post: 它基于这篇文章:

https://medium.com/@sashatran/check-out-the-page-here-7d71a2c43a10 https://medium.com/@sashatran/check-out-the-page-here-7d71a2c43a10

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

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