【发布时间】:2023-04-10 12:18:01
【问题描述】:
复制部分
我正在尝试为 React 应用程序中的某个部分构建某种布局,布局类似于下图,忽略右边的行。 这是我的 HTML, 盒子暂时是空的,稍后再回到那个..
const projects = () => {
return (
<section className="projects">
<div className="container fcontainer">
<div className="fcol fcol--1">
<div className="box-1"></div>
<div className="box-2"></div>
</div>
<div className="fcol fcol--2">
<div className="box-1"></div>
<div className="box-1"></div>
<div className="box-1"></div>
</div>
<div className="fcol fcol--3">
<div className="box-1"></div>
<div className="box-2"></div>
</div>
</div>
</section>
)
}
.fcol {
color: #333;
margin: 1rem;
text-align: center;
font-size: 3rem;
display: flex;
flex-direction: column;
height: 60vh;
flex-grow: 4;
&--1 {
.box-1{
background-color: lightblue;
flex-grow: 1;
margin-bottom: 2rem;
}
.box-2{
background-color: lightgreen;
flex-grow: 2;
}
}
&--2 {
.box-1{
background-color: lightblue;
flex-grow: 1;
justify-content: space-between;
&:not(:last-child){
margin-bottom: 2rem;
}
}
}
&--3 {
.box-1{
background-color: lightblue;
flex-grow: 3;
margin-bottom: 2rem;
}
.box-2{
background-color: lightgreen;
flex-grow: 2;
}
}
}
这是codepen,如果您有兴趣,可以编辑和修复问题,如果您有更好的方法,也可以随意更改 HTML 和 scss 整个结构。
非重复部分
我有点坚持用图像填充每个框,因为即使我手动将其设置为height 和width 到100%,图像总是溢出框外,如果我添加引导类@987654333,它也不起作用@。
在我的 react 应用程序中导入和使用 .scss 文件中的图像时出现另一个错误,请在 link 中查看,就是这样,非常感谢您抽出宝贵时间
【问题讨论】:
-
你有没有运行过代码sn-ps看看它们是否有效?
-
好吧,老实说,我没有在这里运行它,但我确实提供了指向 codepen 中工作示例的链接
-
问题(至少在您的codepen 中)是您对
flex-grow的使用。此属性旨在分配容器中的可用空间。因为中间列有更多的空闲空间(这一列有两个间隙,其他列有一个),所以项目会更小。请改用flex-basis。有关详细信息,请参阅副本。 -
谢谢迈克尔,这有帮助,这个问题实际上由两部分组成,是的,第一部分结果是重复的,但我猜第二部分不是,另外,我实际上提到了另一个问题最后没有人回答,请您考虑检查一下,然后也许您想取消标记它重复,谢谢
-
你好,迈克尔,你能考虑重读我的问题吗,谢谢
标签: css reactjs sass responsive-design flexbox