缩小图像,使其适合静态高度柔性盒



我得到了以下结构:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>

<div class="container">
<div class="flex flex-nowrap flex-col justify-between bg-red-500" style="height: 300px;">
<div class="border">lorem ipsum dolor</div>
<div class="border">lorem ipsum dolor</div>
<div class="border">lorem ipsum dolor</div>
<div class="border">lorem ipsum dolor</div>
<div class="border shrink max-h-full w-auto"><img class="max-h-full object-contain" src="https://picsum.photos/id/237/200/300" /></div>
<div class="border">lorem ipsum dolor</div>
</div>
</div>
</body>
</html>

我希望图像能自动缩小,这样所有的div都能放在flexbox中。显然现在这不起作用。我该怎么做?

好的,我找到了答案(通过https://epndavis.com/blog/contain-an-image-within-fixed-height-flexbox-grow/.我不得不将overflow-auto添加到包含图像的div中。

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>

<div class="container">
<div class="flex flex-nowrap flex-col justify-between bg-red-500" style="height: 300px;">
<div class="border">lorem ipsum dolor</div>
<div class="border">lorem ipsum dolor</div>
<div class="border">lorem ipsum dolor</div>
<div class="border">lorem ipsum dolor</div>
<div class="border shrink overflow-auto"><img class="max-h-full object-contain" src="https://picsum.photos/id/237/200/300" /></div>
<div class="border">lorem ipsum dolor</div>
</div>
</div>
</body>
</html>

尝试使用flex direction属性将其设置为column,这意味着它意味着所有的弹性项目将显示在块中。

相关内容

  • 没有找到相关文章

最新更新