css - 具有 sass 和控制图像溢出的响应式 flexbox

标签 css reactjs sass responsive-design flexbox

<分区>

重复部分

我正在尝试为 React 应用程序中的某个部分构建特定布局,布局类似于下图,忽略右边的行enter image description here 这是我的 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>
  )
}
现在这是我的 .scss 代码

.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;
      }
    }
  }

这是结果.. enter image description here

这是一个codepen如果您有兴趣,可以为你们编辑和解决问题,如果您有更好的方法,也可以随意更改 HTML 和 scss 整个结构。

非重复部分
我有点卡在用图像填充每个框,因为图像总是溢出框外,即使我手动将它的 heightwidth 设置为 100%,如果我添加了 Bootstrap 类 img-fluid,它也不起作用。 在我的 React 应用程序中导入和使用 .scss 文件中的图像时发生另一个错误,请在 link 中查看, 就这样,非常感谢您的宝贵时间

最佳答案

这就是你想要做的吗?

https://codepen.io/t_sg/pen/NEQayz

HTML:

<section class="projects">
  <div  class="container fcontainer">
    <div class="fcol fcol--1">
      <div class="box box-1"></div>
      <div class="box box-2"></div>
    </div>
    <div class="fcol fcol--2">
      <div class="box box-1"></div>
      <div class="box box-1"></div>
      <div class="box box-1"></div>
    </div>
    <div class="fcol fcol--3">
      <div class="box box-2"></div>
      <div class="box box-1"></div>
    </div>
  </div>
</section>

还有 CSS:

.fcontainer {
  display: flex;
  align-items: stretch;
  background-color: #f1f1f1;
  padding: 10px 30px;

  .fcol {
    color: #333;
    margin: 1rem;
    text-align: center;
    font-size: 3rem;
    display: flex;
    flex-direction: column;
    height: 60vh;
    flex-grow: 4;
  }
}

.box {
  margin-top: 10px;
  margin-bottom: 10px;

  &-1 {
    background: lightblue;
    flex: 0 0 33.33%;
    max-height: calc(33.33% - 20px);
  }

  &-2 {
    background: lightgreen;
    flex: 0 0 66.67%;
    max-height: calc(66.67% - 20px);
  }
}

关于css - 具有 sass 和控制图像溢出的响应式 flexbox ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53656833/

相关文章:

html - 去除html中不必要的空白

node.js - 使用 Paypal 安全付款

html - 像 StackOverflow 一样的响应式导航栏

css - 确定 Select 元素是否下拉 - 仅使用 CSS 或 SASS

css - 混淆 CSS 类/样式顺序

javascript - Webpack 2 和 SASS : A SASS script can't find its font dependencies when it is @imported to another SASS file

html - Z-index 不适用于变换和动画

javascript - 悬停时仅显示一个 div

CSS 选择器 li :hover for only when none of its child is hovered

javascript - 使用重组实用程序作为元素