gpt4 book ai didi

css - flex 盒子。元素未在同一高度对齐

转载 作者:行者123 更新时间:2023-11-28 00:32:35 28 4
gpt4 key购买 nike

我创建了一个包装器元素,其中包含 2 个彼此相邻的行内 block 框(图片中为浅绿色和黄色)。然后我创建了另外两个 div,它们都嵌套在其中一个内联 block 中以使内容居中。它可以工作,但由于某种原因,即使我不使用任何边距、填充或绝对定位,我的 flexbox 的垂直位置也会向下移动。如果有人知道为什么会发生这种情况,请赐教!我真的很感激。

视觉表示:

enter image description here

HTML代码:

  <section className="summary">
<div className="summary-wrapper">

<div className="user-wrapper">
<div className="user-wrapper__photo">
<div className="user-wrapper__photo-avatar">
test
</div>
</div>

<div className="user-wrapper__userInfo">
<div className="user-wrapper__userInfo-text">
<div>Rodney Wormsbecher</div>
<div>Software developer</div>
</div>
</div>
</div>

</div>
</section>

SCSS代码:

.summary {
height: 20rem;
background-color: #333;
width: 100%;
display: block;
-webkit-clip-path: polygon(0 0, 100% 0, 100% 85%, 0% 100%);
clip-path: polygon(0 0, 100% 0, 100% 75%, 0% 100%);
padding: 40px;
color: white;

&-wrapper {
width: 100%;
height: 8rem;
// background: red;
}

& .user-wrapper {
display: inline-block;
width: 20rem;
height: 5rem;
background: yellow;

&__photo {
display: inline-block;
background: aqua;

&-avatar {
display: flex;
align-items: center;
justify-content: center;
background: pink;
height: 5rem;
width: 5rem;
border-radius: 50%;
}

}

&__userInfo {
display: inline-block;

&-text {
display: flex;
padding-left: 1.5rem;
height: 5rem;
width: 15rem;
align-items: flex-start;
flex-direction: column;
justify-content: center;

}
}
}
}

最佳答案

我发现带有 display: inline-block 的框需要一个 'vertical-align: top' 属性。然后我不得不重新对齐 flexbox 元素。

更新后的 SCSS:

.summary {
height: 20rem;
background-color: #333;
width: 100%;
display: block;
-webkit-clip-path: polygon(0 0, 100% 0, 100% 85%, 0% 100%);
clip-path: polygon(0 0, 100% 0, 100% 75%, 0% 100%);
padding: 40px;
color: white;

&-wrapper {
width: 100%;
height: 8rem;
// background: red;
}

& .user-wrapper {
display: inline-block;
width: 20rem;
height: 5rem;
background: aqua;
vertical-align: top;

&__photo {
display: inline-block;

&-avatar {
display: flex;
align-items: center;
justify-content: center;
background: pink;
height: 5rem;
width: 5rem;
border-radius: 50%;
}

}

&__userInfo {
display: inline-block;
vertical-align: top;

&-text {
display: flex;
padding-left: 1.5rem;
height: 5rem;
width: 15rem;
align-items: flex-start;
flex-direction: column;
background-color: yellow;
justify-content: center;
}
}
}
}

关于css - flex 盒子。元素未在同一高度对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54330580/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com