First code:
html {
display:flex;
width:100%;
height:100%;
}
body {
display:flex;
flex:1;
}
.container {
display:flex;
flex:1;
overflow-y:auto;
flex-direction:column;
justify-content:center;
align-items:center;
}
.block1 {
justify-content:center;
background-color:green;
display:flex;
width:300px;
min-height:150px;
}
.block2 {
background-color:blue;
display:flex;
min-height:300px;
width:500px;
}
<div class="container">
<div class="block1">
<img src="https://tse2.mm.bing.net/th?id=OIP.M252f960f4a4f32c22914d8d87623f066o0&pid=15.1">
</div>
<div class="block2"></div>
</div>
Run codeHide resultI have two blocks in a container. I want them focused on the screen. The problem is that the screen height is small, I have a scroll bar that appears, but the first block has a part that goes to the screen (invisible).
To play, reduce the height of the jsfiddle preview window. You will understand what I mean by going out on the screen.
The expected behavior is for the scroll bar to display and retain the appearance of the div.
I tried setting flex-shrink to 0 on each element, but it does not work ...
source
share