html - 防止 CSS Flex 在两个轴上拉伸
问题描述
有没有办法防止在 CSS Flex 的两个轴上拉伸?在下面的示例中,我希望选项和框层调整为子项的宽度和高度。此外,我希望该框位于页面中间。
我知道 flex-grow 和基础,但我的理解是它只管理主轴的空间。
.container {
background-color: red;
display: flex;
justify-content: center;
}
.box {
display: flex;
flex-basis: 0;
background-color: green;
justify-content: center;
}
.option {
display: flex;
flex-direction: column;
align-items: center;
background-color: yellow;
}
.img-container {
background-color: blue;
}
.img-container img {
max-width: 100%;
}
<div class="container">
<div class="box">
<label class="option">
Option 1
<div class="img-container">
<img src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/dog-puppy-on-garden-royalty-free-image-1586966191.jpg?crop=0.752xw:1.00xh;0.175xw,0&resize=640:*" />
</div>
</label>
<label class="option">
Option 2
<div class="img-container">
<img src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/dog-puppy-on-garden-royalty-free-image-1586966191.jpg?crop=0.752xw:1.00xh;0.175xw,0&resize=640:*" />
</div>
</label>
</div>
</div>
解决方案
推荐阅读
- android - 横幅广告未显示 Flutter
- python - 矩阵来查找大于和小于变量的数据
- javascript - 动态添加元素的 JS 事件监听器
- f# - 如何在 F# 元组列表中正确键入注释
- bigcommerce - 如何在结帐 Bigcommerce 上删除订单确认消息
- json - 防止 JPA/Hibernate 在更新时插入空值
- sublimetext3 - SublimeMerge 上的标尺
- php - Laravel hasMany 基于附加关系的条件
- node.js - 如何从 mongodb 获取最后 10 条消息?
- python - 如何将实例属性带入 @staticmethod