With JSX and CSS in React, I have the ability to easily generate two columns, but unfortunately cannot achieve the same fluid

I am attempting to create a layout with three columns of text fields and labels. While I can easily achieve this with two columns, the third text field is appearing on a separate row below:

 <div className={styles.threecol}>
       <div className={styles.col1}>
             <div style={{width: '150px'}}>
                 <Label className={styles.questionTitle}>Record No.</Label>
                     <TextField
                         value={this.state.Title}
                         disabled={true}
                      />
                   </div>
                 </div>

              <div className={styles.threecol}>
                 <div className={styles.col2}>  

                  <div style={{width: '150px'}}>             
                
                    <Label className={styles.questionTitle}>Room</Label>
               
                    <TextField
                      value={this.state.Room}
                      onChange={this._onRoomChange}
                    />
                    <br />
                  </div>
                </div>
               
              </div>
              <div className={styles.threecol}>
                 <div className={styles.col3}>   

                  <div style={{width: '150px'}}>               
           
                    <Label className={styles.questionTitle}>Room</Label>
              
                    <TextField
                      value={this.state.Room}
                      onChange={this._onRoomChange}
                    />
                    <br />
                  </div>
                </div>
              </div>
             </div>
            </div>
          </div>

The CSS styling:

.threecol {
      overflow: hidden
    }
    
    .threecol .col1 {
      width: 22%
    }
    .threecol .col2 {
      width: 22%
    }
    .threecol .col3 {
      width: 22%
    }
    
    .threecol .col1 {
      float: left;
    }
    
    .threecol .col2 {
      float: none;
    }
    .threecol .col3 {
      float: right;
    }
    
    .threecollabel {
      font:'24px';
      font-weight: 'bold';
      display: block;
    }

    .threecol .co1Sm {
      float: left;
      width: 200px;
      height: 30px;
    }

I have successfully implemented a two-column layout using similar CSS and JSX techniques, but struggling to achieve it with three columns. Here's the simplified JSX code for two columns:

   <div>
      <div>
        <Label className={styles.questionTitle1}>Details</Label>
       </div>
        <div className={styles.twocol}>
          <div className={styles.col1}>
               
             <div style={{width: '150px'}}>
               <Label className={styles.questionTitle}>Record No.</Label>
                  
                 <TextField
                   value={this.state.Title}
                   disabled={true}
                  />
                </div>
               </div>
              <div className={styles.twocol}>
                 <div className={styles.col2}>               
                 
                  <div style={{width: '150px'}}>
                    <Label className={styles.questionTitle}>Room</Label>
                 
                    <TextField 
                      value={this.state.Room}
                      onChange={this._onRoomChange}
                    />
                    <br />
                  </div>
                </div>
              </div>
             </div>
            </div>

I prefer not to utilize tables for this design.

T

Answer №1

@Sarah, I noticed that you are closing multiple div tags in your HTML code. Additionally, you are applying float: none to the second column style col2, which could be causing the issue.

.threecol .col2 {
  float: left;
  text-align: center;
}

Reference: https://stackblitz.com/edit/react-3urqg6?file=index.html

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

How do I adjust the ul size to be proportionate to the header?

I have a list with corresponding hyperlinks in my code, and I am trying to make these elements the same size as the header. I attempted adding auto padding and height auto but it did not produce the desired result. Here is the HTML snippet: <header id ...

The onChange method in React is failing to execute within the component

I am having trouble overriding the onChange method in a component. It seems like the method is not triggering on any DOM events such as onChange, onClick, or onDblClick. Below are the snippets of code where the component is rendered and the component itsel ...

When clicked, the size of a link will adjust

Having trouble with my code and CSS. The pagination in Vue is working fine, but the links are changing size on certain pages. When clicking on the first or second number, the links remain the same size. However, when clicking on the third or fourth link, ...

Utilizing HTML/CSS to display text and an image positioned above a sleek navigation bar

I am struggling to align a logo on the left side of my website, with text on the right next to it, all placed above the navigation bar. Despite my efforts, I just can't seem to get them positioned correctly! CSS .headerLogo{ float:left; marg ...

Struggling to align a section in the middle of an image in next.js

Hello everyone, I'm new to using Next.js. Currently, I have the HomePage located within the pages folder. My issue is that I am attempting to center the <h1></h1> in the middle of the picture but instead, it keeps pushing it down. Below is ...

How to align an image in the center of a circular flex container

I'm facing an issue in my Angular project where I have the following code snippet: onChange(event: any) { var reader = new FileReader(); reader.onload = (event: any) => { this.url = event.target.result; }; reader.readAsData ...

troubleshooting issues with css overflow-x scroll functionality

I need assistance with aligning two divs side by side using the display:inline-block property. However, I am facing an issue when applying overflow-x:scroll to the main container. When the screen size is reduced, one of the div elements moves below the oth ...

The input field will display a border when it is actively selected

I am currently designing a form where the label should be positioned on the top border line of the text box. [![enter image description here][1]][1] Here is the code snippet: <div class="container"> <div class="row"> ...

Ways to incorporate text as a background instead of relying on an image in CSS

As the title suggests, I am trying to figure out how to use text as a background instead of an image for my little application. I am currently customizing a drop-down button by changing the button to an upside-down triangle using HTML code ▼. Instead ...

React Jest is experiencing an error at line 246 in the internal process promises module, triggering an uncaught exception with the specified error

In my React code snippet below, I am using the useEffect hook with an async function to fetch data: useEffect(() => { (async () => { await httpClient .get(`${config.resourceServerUrl}/inventory/`) . ...

Modifying an image's height and width attributes with jQuery and CSS on click action

I'm currently developing a basic gallery using HTML, CSS, and jQuery. The objective is to have a larger version of an image display in a frame with an overlay when the user clicks on it. While this works flawlessly for horizontally-oriented images, ve ...

Ways to retrieve the baseURL of an axios instance

This question is being posted to provide an easy solution for fellow developers who may be looking for an answer. //Suppose you have an axios instance declared in a module called api.js like this: var axios = require('axios'); var axiosInstance ...

Adding an image to a server through PHP in the TinyMCE editor

Currently, I am in the process of utilizing TinyMCE text editor for uploading images using PHP and JS database. However, I find myself perplexed when it comes to sending the image to the server. Below is the snippet of the JS code being used: <script ...

Creating a web app using React frontend, Spring Boot backend, and MongoDB database

I have developed a React application with create-react-app. Now, I am seeking a way to package the application into a single executable file to share with my friend without dealing with numerous files and dependencies. The application does not need to be o ...

The innovative dual-scroll feature on Instagram's profile page revolutionized the way users navigate

Currently experiencing challenges in creating a social app similar to Instagram and Twitter. I am having difficulty replicating the profile page layout on Instagram and it's unclear how they achieved it. see image here The scroll bar on the profile ...

The form submission did not yield any results

function calculateCost() { var projectorCost=0,price=0,quantity=0,discountPrice=0,totalCost=0; var modelName=document.getElementById('projectormodel').value; var quantity=document.getElementById('q ...

How do I retrieve the return value of another function in React?

I am working on a function called HandleCitiesArray where I need to access the myCitiesArray. To achieve this, I want to utilize the useSelector hook from Redux. Specifically, I aim to remove an object from initialState.myCities array. How can I go about ...

Create a search feature using Javascript and React that retrieves and displays results from a

I am currently developing a React application with a search feature that fetches JSON data and displays matching search results on the website import { React, useState } from 'react'; export default function PractitionerSearch() { const [data ...

Disabling specific time slots in TimePicker Material UI

I have an array of time slots that I want the user to select from, for example: var arr = ["11:00:00","11:10:00","13:00:00"] How can I disable all other time slots on the TimePicker and only enable these specific time slots? This is my TimePicker compone ...

There seems to be a malfunction in the Form component when utilizing React Js in conjunction with Material

I'm a beginner in React JS and material UI, and I'm facing an issue where the value I type in the text field is being captured (debugged and checked), but it's not displaying in the form. Please take a look at the code below. Although I am ...