Tips for adjusting column width with flexbox intersections

I am currently working on a React web application that has minimal styling. I have divided the content into 3 columns, with the leftWrap being col-3, rightWrap being col-4, and the remaining width is for centerWrap. I want to apply flexbox to these columns without knowing their exact class names. How can I achieve this?

 <div className={styles.Home__wrapper}>
      <div className={styles.Home__leftWrap}> .... </div>
      <div className={styles.Home__centerWrap}> .... </div>
      <div className={styles.Home__rightWrap}> .... </div>
    </div>

.Home {
 &__wrapper {
  display : flex;
  flex-wrap: nowrap;
  width : 100%;
  box-sizing: border-box;
 }

 &__leftWrap {
  display : flex;
 }
 &__rightWrap {
  display : flex;
 }
 &__centerWrap {
  display : flex;
 }
}

Is it possible to set the width for each column className based on the classes mentioned above using the calc() method?

Answer №1

To create a responsive layout, set the display CSS attribute of the container div to flex and adjust the flex attribute of the child elements accordingly. The total width of the children elements will be calculated based on the sum of their individual flex values, with the remaining space allocated accordingly. In your scenario, the left and right children have fixed widths, while the center element should take up the remaining space, so assign a flex value of 1 to the center element.

._wrapper {
  display : flex;
  flex-wrap: nowrap;
  box-sizing: border-box;
 }

 ._leftWrap {
  width: 50px;
  background-color: red;
 }
 ._rightWrap {
  width: 100px;
  background-color: blue;
 }
 ._centerWrap {
  flex: 1;
  background-color: yellow;
 }
<div class="_wrapper">
      <div class="_leftWrap"> .... </div>
      <div class="_centerWrap"> .... </div>
      <div class="_rightWrap"> .... </div>
    </div>

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

Tips for preventing issues with Javascript latency causing flash out during page loading in Chrome

When building a page with Vue.js or any other Javascript, the issue of temporary flash during loading on Chrome due to constructing latency can be quite frustrating. This delay is not caused by asynchronous ajax requests, but rather the processing involv ...

Error: Unable to locate module: File not found at './data:application/font-woff;charset=utf-8;base64,`

Encountered an issue with swiper in my Next.js project. "next": "^12.0.3", "swiper": "^7.2.0" I have the specified versions installed and need a solution to resolve this error. Error message: Module not found - Ca ...

Decoding SQS POST messages using node.js

I am faced with the challenge of setting up communication between a web server and a worker using an SQS. The process involves uploading an image to an S3 bucket through the server, which then sends a message to the SQS for the worker to retrieve, resize, ...

Incorporate the slick-slider functionality smoothly into a WordPress website by utilizing JavaScript

I am fairly new to .js and currently attempting to incorporate a .js slider into my Wordpress site. I have been working on getting Slick-Slider operational on a website. While it functions perfectly fine on my static webpage, the transition to Wordpress ha ...

How can I enable a button in a React application when the text input is not populating

For my Instagram MERN project, I have implemented a Comment box feature for users. The Post button starts off disabled and becomes enabled when text is entered. However, despite entering text, the button remains disabled, preventing submission. Below is th ...

Display a div when hovering over a span with custom styling

Don't let the title fool you. http://jsfiddle.net/whb8A/ I'm struggling to style the text inside a span tag within a div. The h3 element shouldn't be nested in the span, but removing it makes it difficult to style with CSS. When hovering ...

Send backspace key press event to the applet and prevent it from continuing

I am struggling with a Java applet on my webpage that allows users to edit text. Whenever a user tries to modify the text by pressing the backspace button, the browser mistakenly forwards to the previous page. I attempted to filter out the backspace key pr ...

Attempting to utilize ng-click on an element that has been added using element.append() in the postlink phase?

I have been working on customizing a particular angular library to incorporate some new features. https://github.com/southdesign/angular-coverflow/blob/master/coverflow.js As part of this process, I am looking to attach click events to the elements being g ...

Achieve full height for div without causing it to expand (utilize scrollbar for overflow)

I am looking to achieve a specific layout for my webpage, as shown in the image below: The layout depicted in the image above is created using the following HTML and bootstrap classes: <div className="ContentWrapper d-flex mh-100 flex-row h-10 ...

Send dropdown selections to a Javascript function and convert them into an array

Within my JavaScript function, I need to pass multiple selected values from dropdown menus and store them in a JavaScript array. Each time a value is selected and sent using the onchange() function, it should be added to the array. If the same value is sel ...

send multiple textbox values to controller in CodeIgniter

I am new to Codeigniter and I'm facing some difficulties in understanding how to accomplish a task. In my view page, there are five rows generated using a for loop. Each row consists of two select boxes and two input boxes. I don't know how to re ...

Avoid multiple delays when clicking the identifier

I came across this code snippet: $(element).on('click', function() { $this.closest('div').before('<span id="message" style="display:none"></span>'); $('#message').fadeIn().delay(5000).fadeOut(); ...

Identical code exhibiting varying behavior between localhost:3000 and the production server at localhost:5000 on the web

I'm currently in the process of learning React Js, but I've been encountering a persistent error that has me stumped. A specific component functions perfectly when running on my local server (localhost:3000), but as soon as I try to deploy it to ...

Getting the value of a hidden input field within a div by accessing the event.target that initiated the event in JavaScript

I am working with a set of li elements, each containing specific child elements structured like this: <li class="list"> <!--Parent--> <input type="hidden" id="id" value="3"> <!--Child 1--> <div class="cd-1">....</div ...

Error: TypeScript cannot locate the specified <element> in the VSCode template

After conducting some observations, I've come to realize that the error is specific to the first .tsx file opened in VSCode. Once IntelliSense runs on this initial file, the error appears. Subsequent files work fine without any issues. To troubleshoo ...

Tips on utilizing recursive Promises within a loop while transferring arguments to another function

Despite searching other threads on SO, I couldn't find a satisfactory answer to my problem. Every solution seems to be missing something essential for my case, especially since none of them address Apple Music specifically. The Apple API relies heavil ...

I am having trouble with my custom-button class not successfully overriding the btn background color property. Can anyone provide insight

Utilizing the bootstrap5 variant-button mixin, I aim to create a custom-colored button. While I have successfully altered the default hover effect color, I am encountering difficulty in setting the background color of the button itself. Upon inspecting the ...

How to Perform a Method Call or Array Iteration in JSX within HTML

Encountering a new issue that I haven't faced before, this is my first time working on something like this and finding a solution is proving to be tricky. Currently, I'm using SendGrid to send an HTML email through a POST request in express on N ...

The bottom of the page displays varying outcomes between Code Snippet (CodePen) and Angular

I had the idea of having my footer cover the entire length of the page and stick to the bottom, adjusting itself if more content is added. However, I encountered an issue where on Codepen everything works perfectly, but on Angular (14), the footer does not ...

the navigate feature is not redirecting to the intended page as expected

I am currently working on a React application and facing an issue with configuring the navigation. The problem lies in the code of the Navbar component, where upon clicking the logout button, the authentication context should be cleared and the user should ...