Aligning a div vertically with two text areas inside

I am having difficulties with vertically centering my div, which is currently acting as a container for two text areas. The two text areas are positioned side by side as I want them, but I would like them to be vertically centered on the screen while maintaining their relative positions. How can I achieve this?

App.js

class App extends React.Component {
  state = {
    character: null
  };
  render() {
    return (
      <div className="Centre">
        <div className="Left">
          <TextBox
          />
        </div>
        <div className="Right">
          <textarea
            className="Box"
            placeholder={"English translation"}
            value={this.state.english}
          />
        </div>
      </div>
    );
  }
}

export default App;

App.css

.Box {
  height: 100px;
  width: 98%;
  padding: 1%;
  border: solid 1px orange;
}

.Centre {
  width: 800px;
  height: 400px;
  margin: 0 auto;
}

.Left {
  width: 300px;
  height: 200px;
  float: left;
  border: red;
}

.Right {
  width: 300px;
  height: 200px;
  float: Right;
  border: red;
}

textbox.jsx

class TextBox extends React.Component {
  render() {
    return (
      <form>
        <textarea
          className="Box"
          placeholder="Type in Spanish"
          value={this.props.equation}
          type="text"
          name="equation"
        />
      </form>
    );
  }

Answer №1

Update your CSS styling

.Box {
  height: 100px;
  width: 98%;
  padding: 1%;
  border: solid 1px orange;

}

.Centre {
  height:100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.Left {
  width: 300px;
  border: red;
}

.Right {
  width: 300px;
  border: red;
}

Check out the live demo here

Answer №2

Assuming I understood your question correctly, one way to achieve this is by utilizing the flex property to center elements within a div:

.Middle {
    display: flex;
    align-items: center;
}

Answer №3

To achieve center alignment with the use of flexbox, apply align-items property to the parent element having the class name Centre:

display: flex;
align-items: center.

Answer №4

<div id="main-wrapper">
  <div class="input-container">
     <input type="text" placeholder="input 1"> 
     <input type="text" placeholder="input 2"> 
  </div>
</div>

#main-wrapper {
    max-width: 80vw;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.input-container{
  display: flex;
  flex-direction: row;
  justify-content: space-around;
} 

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 personalizing the icon on muidropdown

<FormControl variant="filled" sx={{ m: 1, minWidth: 120 }}> <InputLabel id="demo-simple-select-filled-label">Age</InputLabel> <Select labelId="demo-simple-select-filled-label" id=" ...

What is the best approach for incorporating sub-navigation within a page popup in a Next.js project?

In the midst of my Next.js project, there is a requirement to showcase a chat popup consisting of multiple sub-pages like user registration, conversation page, and more. Hence, seamless navigation inside this popup is necessary. The idea is not to alter th ...

Exploring the integration of Structr with ReactJS, leveraging RESTful APIs

Is there a method for integrating Structr with frontend frameworks like ReactJS, Vue, etc? I am looking to develop a standalone React app that communicates with Structr solely through a RESTful API. What is the process for connecting a separate frontend ...

Is there an alternative to translate3d that I should consider using?

When the code transform: translate3d(0,0,0); is included, it prevents position:fixed; from working. After removing it, I am able to use position:fixed; once again. However, there is now an issue with my navigation bar, as it relied on the transform code to ...

What is the best way to vertically align two divs on the left and right?

Having trouble aligning my dropdown list vertically with my textarea on the left. It seems like they are clashing together for some reason. UPDATE: Thank you for the assistance, I was able to make the necessary adjustments. JSP: .ExeDropdown{ float: ...

Why does the getComputedStyle function return null for IE11 and Edge when using Kendo React Grid within a Popout window, while it works fine in Chrome, Opera, and Firefox?

Check out my stackblitz demo where I am experimenting with rendering a Kendo React Grid inside a popout window using the react-popout-component. The demo runs smoothly in Chrome, Opera, and Firefox, but encounters issues in Edge and IE11 due to a null valu ...

"TypeScript error: Arrays in interfaces are found to be undefined and not compatible

I'm struggling with correctly implementing the Typescript React Props syntax. In my project, I have an array of people, each of whom may have zero to many cars. There is a people container that holds all the people, each person has a car container tha ...

jQuery not functioning properly when included in a separate JavaScript file

I'm facing an issue with my jquery code not working properly when I place it in a separate js file instead of embedding it directly into the html. Currently, my setup looks like this: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3 ...

Effortlessly transferring images using Axios in Node.js: A guide

Previously, I utilized ApiSauce to send listings from my React Native application to a Node.js server with Multer. I made the switch to Axios, and everything went smoothly except for the image uploading component. export const add = (listing, onUploadPro ...

I developed a Node.js Express server that establishes a connection to a MongoDB database hosted on mLab. I am now looking to integrate CRUD operations with this server from my React application. Can anyone

I built one nodejs app that uses express routing to connect to a mongodb on mlab that listens on a local port. I built a React app with nodejs that is listening on another port. How can I have the React app read and write documents to the database? Any tu ...

How is performance impacted by z-index?

What is the impact of using high z-index values in CSS on performance? If a webpage contains multiple images, does setting z-index values as high as 10,000 affect performance? For instance, if a page has 15 images with z-indexes ranging from 500 to 10,00 ...

Using CSS to automatically adjust the width of a child div based on its content, rather than stretching it to fill the entire

I'm currently facing an issue with my CSS. Apologies for the vague title, but I'll do my best to explain it here. My problem lies within a parent wrapper div that is centered on the page. Within this wrapper, there is another child div containing ...

Position two div elements and an hr tag to create a step progress bar

Check out my progress bar design https://i.sstatic.net/u9SRM.png How can I center the 'created' and 'assigned' divs below the circle while ensuring the 'hr' line touches the circle, and it is responsive across different scre ...

What is the best method to center a div on the screen?

Is there a way to have a div open in the center of the screen? ...

When using NextJS with Redux Persist, the HTML does not get rendered in the initial server

I am currently utilizing ReactJS/NextJS along with Redux and redux-persist, as well as Ant Design. Recently, I have noticed that my html codes and other data are not rendering in the page's source. They do render in the browser and when inspected, but ...

What is the method for obtaining the CSS text content from an external stylesheet?

I've spent countless hours trying to achieve the desired results, but unfortunately, I haven't been successful. Below is a summary of my efforts so far. Any helpful tips or suggestions would be greatly appreciated. Thank you in advance. Upon rec ...

Changing the onClick event to onMouseEnter/onMouseOut in a Tailwind-UI component: A step-by-step guide

Looking for help with implementing a store navigation Tailwind UI component found here: I need the menu categories (Women/Men) to open when I hover over them, and close when I move my mouse away; not open/close on click. Any advice on how to achieve this? ...

Version 5.3 of Bootstrap is now compatible with React JS 18. Additionally, you can now easily customize variables in SCSS by overwriting _variables

Greetings! I am looking to customize Bootstrap 5 variables. I copied the default variables file from this link. However, when I pasted the code into my custom file, I encountered the error shown in the screenshot below: https://i.sstatic.net/o8lLB.png T ...

Changing the direction of the submenu to the left instead of the right

My Bootstrap 4 menu has a submenu that appears to the right of the main menu. However, since the menu is positioned on the far right of the screen, it gets cut off on the right side. I'm looking for a way to make the submenu appear on the left side o ...

Steps to Delete Branding WHMCS Ver 8.1 "Powered by WHMcomplete solutions"

As a newcomer to this community, I am reaching out for the first time seeking assistance. A friend of mine recently updated his WHMCS to the latest version and encountered a branding line above the footer area. Previously, he could remove it by editing th ...