首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flex列强制隐藏柔性盒的初始项。

Flex列强制隐藏柔性盒的初始项。
EN

Stack Overflow用户
提问于 2022-01-22 22:11:27
回答 1查看 51关注 0票数 0

我有一个边栏,它使用FlexBox列布局构建,如下所示:

代码语言:javascript
复制
.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布局时,如下所示:

代码语言:javascript
复制
.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实现同样的功能,以及在应用柔性盒时,究竟是什么在推动图像被切断。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-23 01:53:55

我为您创建了这个html代码和CSS:

代码语言:javascript
复制
.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%);
}
代码语言:javascript
复制
<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>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70817551

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档