css - CSS:`min-height: min-content` 不适用于 `flex-row`
问题描述
当父 flex 元素的高度设置为小于最小高度时,预期结果应该是元素扩展以包含其内容。这适用于flex-direction:row
and min-width: min-content
,但使用字面上相同的代码,但使用column
而不是row
和min-height
而不是min-width
不会导致父元素扩展,而是保留其原始高度并剪裁其子元素。
.flex-row{
display: flex;
flex-direction: row;
justify-content: space-around;
height : 200px;
border-style: solid; border-width: 2px; border-color: black;
/* Width is set to 100px but because the min-content is 600px, the width overridden. */
min-width: min-content;
width: 100px;
}
.block-row{
align-self: stretch;
background-color: red;
width: 300px;
border: 2px solid blue;
}
/* Literally same code except flex-col and min-height */
.flex-col{
display: flex;
flex-direction: column;
justify-content: space-around;
min-height: min-content;
border-style: solid; border-width: 2px; border-color: black;
}
.block-col{
align-self: stretch;
background-color: red;
height: 300px;
border: 2px solid blue;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>min-content :(</title>
</head>
<body>
Intended effect works with flex-row min-width
<div class="flex-row" style="width: 100px; height : 200px; ">
<div class="block-row"></div>
<div class="block-row"></div>
</div>
</br>
Doesn't work with same code except min-height :(
</br>
-> Height is set to 100px, but instead of min-height of children causing height to grow, it is stuck at 100px for some reason.
</br>
<div class="flex-col" style="height: 100px; width : 200px; ">
<div class="block-col"></div>
<div class="block-col"></div>
</div>
</body>
</html>
解决方案
而不是使用 px 使用 vh 允许您使用容器中的 relavite 空间
推荐阅读
- firebase - 卸载错误消息的 Firebase 扩展
- sql - Oracle 分组未捕获所有行
- reactjs - ESLint:Typescript React 中的“道具验证中缺少.map”(eslint react/prop-types)
- typescript - 将 gitlab 中的私有仓库导入 Deno
- python - 如何在 Python 3 中解码和可视化 DICOM 曲线数据?
- mysql - 如何为另一个表结合 MYSQL Left Join 和 Group By
- symfony - 从 symfony 激活 Api 平台上的 graphql 时出错
- discord - discord.js "displayAvatarURL" 低分辨率
- python-3.x - 将当前状态更改为在线
- c - 有没有办法在 C 中“覆盖”原始类型?