【发布时间】:2019-01-23 15:28:55
【问题描述】:
我创建了一个包装器元素,其中包含 2 个彼此相邻的内联块框(图中为浅绿色和黄色)。然后我创建了另外两个 div 都嵌套在一个内联块中以使内容居中。它可以工作,但由于某种原因,即使我不使用任何边距、填充或绝对定位,我的 flexbox 的垂直位置也会向下移动。如果有人知道为什么会发生这种情况,请赐教!我真的很感激。
视觉表现:
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;
}
}
}
}
【问题讨论】:
-
请你用渲染的css创建一个minimal reproducible example
-
我会试试它是一个 React 应用程序,所以需要解决一些问题。
-
提供。请注意,我也包括了我的 css 重置。 codepen.io/anon/pen/gqpYNe