【发布时间】:2021-01-05 12:33:03
【问题描述】:
在过去的几天里,我认为我遇到的问题与我正在使用的 API 有关,但在偶然发现这个 article talking about flex:1 issues 之后,我发现它不是。 文章解决了这个问题,但没有解决图像问题?
HTML
<div className="App">
<div className="box1">
<img src={image} />
</div>
<div className="box2" />
<div className="box3" />
</div>
Scss
.App {
height: 100vh;
width: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
.box1{
flex: 1;
background: blue;
display: flex;
flex-direction: column;
img{
margin: auto;
width: auto;
height: auto;
max-width: 100%;
max-height: 300px;
//try max height 100% breakesit
//max-height: 100%
object-fit: cover;
background-repeat: no-repeat;
}
}
.box2{
background: purple;
height:200px;
}
.box3{
background: green;
height: 250px;
}
}
我希望图像占据父 div 高度的 100%,这可能吗?
【问题讨论】:
标签: html css reactjs sass flexbox