我有一个边栏,它使用FlexBox列布局构建,如下所示:
.SideBarContainer {
// flex-grow: 1;
width: 100%;
height: 100%;
// display: flex;
// flex-direction: column;
padding: 0.5rem 1rem;
align-items: center;
justify-content: space-evenly;
overflow-y: auto;
overflow-x: hidden;
font-family: $font-family;
}看起来:

这就是我注释掉flex布局的时候(理想情况下,我想保留这个布局)。但是,当我启用flex布局时,如下所示:
.SideBarContainer {
// flex-grow: 1;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
padding: 0.5rem 1rem;
align-items: center;
justify-content: space-evenly;
overflow-y: auto;
overflow-x: hidden;
font-family: $font-family;
}由于某些原因,它强制将图像移到顶部,并且不能滚动到视图:

一种方法是摆脱柔性盒,并以某种方式将项目对齐到中心,但我更感兴趣的是,如何使用flexbox实现同样的功能,以及在应用柔性盒时,究竟是什么在推动图像被切断。
发布于 2022-01-23 01:53:55
我为您创建了这个html代码和CSS:
.main {
width: calc(100%/3 + 60px);
font-family: 'Jost', sans-serif;
}
.SideBarContainer {
display: flex;
flex-direction: column;
}
.name {
margin: 0;
font-size: 30px;
}
.desig {
color: #bcbcbc;
font-weight: 600;
}
.profile-img {
border-radius: 100%;
height: 100px;
width: 100px;
object-fit: cover;
}
.btn {
background-color: #f5f5f5;
color: #000000;
display: inline-block;
text-align: center;
text-decoration: none;
font-size: 16px;
padding: 4px 20px;
margin: 10px 0;
width: fit-content;
box-shadow: 0 0 5px 0 rgb(0 0 0 / 20%);
}
.btn.dark {
background-color: #000;
color: #f3ff26;
text-transform: capitalize;
font-weight: 400;
font-size: 18px;
width: calc(100% - 60px);
border-radius: 8px;
box-shadow: 0 0 5px 0 rgb(0 0 0 / 20%);
}<div class="main">
<div class="SideBarContainer">
<img src="https://via.placeholder.com/150x150" class="profile-img" />
<h6 class="name">Rampy sharma</h6>
<span class="desig">Individual Singer</span>
<a href="javscript:void(0);" class="btn">Edit</a>
<p>It is a long established fact that a reader will be distracted by the readable that it has a more-or-less normal distribution of letters, as opposed to using 'Content here.</p>
<a href="javscript:void(0);" class="btn dark">portfolio</a>
</div>
</div>
https://stackoverflow.com/questions/70817551
复制相似问题