Sass and responsive flex boxes allow for the easy control of image overflow

Duplicate part

Looking to create a unique layout for a section within my React application that resembles the image below. Please disregard the lines on the right. https://i.sstatic.net/rfgGy.png Here is the initial HTML structure, with placeholder boxes awaiting content.

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>
  )
}
Below is the corresponding .scss code:

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

And here is the current output:https://i.sstatic.net/Dw7jj.png

A CodePen link has been provided for editing and issue resolution. Feel free to modify the HTML and scss structures as needed.

Non-duplicative part
Experiencing difficulties in inserting images into each box without them overflowing or encountering errors when importing from a .scss file in my React app. More details can be found in this link. Thank you for your assistance.

Answer №1

Are you attempting to achieve this particular layout?

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

The structure of the HTML is as follows:

<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>

Here is the corresponding 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);
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Script tag in NextJS

After numerous attempts, I am still struggling with a specific task on this website. The challenge is to insert a script tag that will embed a contact form and newsletter sign-up form, among others, on specific pages of the site. For instance, the contact ...

Click here to get the button click link

Is there a method to obtain the link of a button click on a website? This is the Website and it features a play button. I am looking for a way to capture the link triggered by clicking the play button so that the audio starts playing automatically each t ...

Using Javascript and JQuery to create an alert that pops up upon loading the page is not effective

I am having trouble making an alert show up when my website loads. The Javascript code is functional when directly included in the HTML, but once I move it to a separate file named script.js and link it, nothing happens. Can someone please help me identify ...

Utilize React to access an external variable that has been declared outside of the root component

My React application is bundled and loaded into an HTML file using a script tag. I need to pass some initial data to the application, and I am looking for suggestions on how to define this data either in the HTML itself or in previously loaded JavaScript f ...

Setting up a middleware file for your nextJs project: A step-by-step guide

Currently, I am deep into a project that involves using Next.js. Progress has been steady so far, but there's a hitch with my middleware.ts file. Despite diligently following the Middleware documentation, it seems like the middleware is not triggering ...

Issues with the proper display of Bootstrap 4 in Django are causing problems

I am currently in the process of setting up Django to work with Bootstrap. Despite my efforts, I can't seem to get it functioning correctly and I'm unsure of where I may be making a mistake. Initially, I am just trying to display a panel. You can ...

Using jQuery to modify a CSS property when a specific option is chosen

I'm currently working on creating an option dropdown menu and I've hit a roadblock trying to display a textbox only when the 'other' option is selected. Here's what I have so far: <span id="con-country"><label for="count ...

How can I stop React from automatically scrolling the page when re-rendering?

Encountered a perplexing issue with React - it automatically scrolls the page upon re-render. Check out the demo app on CodeSandbox - https://codesandbox.io/s/react-scroll-bug-demo-y7u50j?file=/src/App.js To replicate the problem, follow these steps: Sc ...

Incorporate a JSON file into the Webpack output separately from the bundle.js file

Is there a way for my webpack application to read a JSON file at runtime without including it in the bundle.js after packaging? I want the JSON file to be available in the package folder but not bundled with the rest of the code. How can I achieve this? ...

I'm looking to have a span and an input side by side, both spanning the full width of the containing div. How can I achieve this?

In my code snippet below: <html> <body> <div style="width: 700px;"> <span>test</span> <input style="width: 100%;"></input> </div> </body> </html> I am facing an issue where the span and input el ...

What is the best way to display a string as a component in React?

Having trouble importing navigation links and corresponding material icons dynamically from a JSON file to render them as MUI components. Seeking assistance with this issue. What is needed? Dynamically import icons from the JSON file. Render MUI componen ...

Exploring ways to utilize Tailwind CSS breakpoints within the style object in JSX/React applications

I'm facing a dilemma with styling a <div> tag in my React component. I want to apply some custom styles, but I am unsure if it's possible to incorporate Tailwind CSS screen-size breakpoints into the mix. Take for example this snippet of cod ...

Updating a text input's placeholder using Bootstrap4

Bootstrap 4 provides classes like text-left and text-right for aligning text inside an input field. Is there a Bootstrap-friendly method to only align the placeholder text in an input without affecting the alignment of the actual text? ...

Establish a predetermined selection for a radio button and its associated checkbox option

I am working on a React material UI group input field that is mapping a dataset. The result consists of one radio button and one checkbox performing the same action. Initially, I attempted to set the state to establish one data item as default. While I fol ...

Aligning the content in the center of a div with inline display

Hi there, I have a quick question for the experts out there. I'm new to all of this so please bear with me :) I'm attempting to center an inline social sharing div on my website, but it's proving to be quite challenging. The div is nested w ...

Tips for dynamically changing the style (color/fill) of material-ui elements when generating them within a map function

I am struggling to dynamically change the style (colors) of elements in list items generated from a map function that includes rgb-color values. While using classes can work, trying to dynamically set the style based on the data/color provided in the objec ...

Is there a way to arrange list items to resemble a stack?

Typically, when floating HTML elements they flow from left to right and wrap to the next line if the container width is exceeded. I'm wondering if there's a way to make them float at the bottom instead. This means the elements would stack upward ...

Whenever I find myself being redirected to the login page, my goal is to eliminate the bottomTab from view

I'm looking to eliminate the bottom tab when I land on the login page, even though I've set it up for all pages. However, whenever I click on the login button, the tab remains visible. Here is my current code: import React, { useContext } from & ...

Tips for updating data in a GraphQL query using the refetchQueries method with specific arguments

Can someone help me figure out how to properly pass an argument in the refetchQueries method in Apollo? Here is the code snippet: submitForm(e) { e.preventDefault(); this.props.addAppleMutation({ variables: { ...

The Bootstrap tabs are not correctly displaying the content

Hey there, I'm currently working on a project that involves using bootstrap tabs (BS4) within a form. One of the requirements is to have forward and back buttons for form navigation, and I'd like to leverage BS4's tab('show') fun ...