我有一個使用 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 布局(理想情況下我想保留)的時候。但是當我啟用彈性布局時,如下所示:
.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 并以某種方式將專案對齊到中心,但我更感興趣的是了解如何使用 FlexBox 實作相同的效果,以及在應用 flexbox 時究竟是什么推動影像被切斷。
uj5u.com熱心網友回復:
我為你創建了這個 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://www.uj5u.com/qukuanlian/419391.html
標籤:
