How to align two div elements side by side using React

My goal is to showcase the content of two div elements in a single row, so I decided to enclose them within another div and adjust its display property to flex. However, despite both divs being displayed on the same row, they appear stacked on top of each other instead of side by side.

https://i.sstatic.net/WqT2b.png

I followed this suggestion, but unfortunately it did not yield the desired result.

This snippet showcases the code for my component:


            <TableFooter>
                <TableRow>
                  <div className="crud-footer">
                    <div className="col-6">
                      <TablePagination
                        count={data.length}
                        rowsPerPage={rowsPerPage}
                        page={page}
                        onChangePage={this.handleChangePage}
                        onChangeRowsPerPage={this.handleChangeRowsPerPage}
                      />
                    </div>
                    <div className="col-6 crud-controls">
                      <Fab className="jr-fab-btn bg-blue text-white">
                        <i className="zmdi zmdi-plus zmdi-hc-fw"/>
                      </Fab>
                      <Fab className="jr-fab-btn bg-yellow text-white">
                        <i className="zmdi zmdi-edit zmdi-hc-fw"/>
                      </Fab>
                      <Fab className="jr-fab-btn bg-red text-white">
                        <i className="zmdi zmdi-delete zmdi-hc-fw"/>
                      </Fab>
                    </div>
                  </div>
                </TableRow>
              </TableFooter>

Additionally, here is the associated css styling for the divs:

.crud-footer {
  display: flex;
  flex-direction: row;
}

.crud-controls {
  display: flex;
  text-align: right;
}

Answer №1

Without having insight into the specific CSS framework you are utilizing, it becomes challenging to pinpoint the exact issue at hand.

Upon initial inspection of the classes used in your code, it appears that there may be a missing parent row class within the crud-footer div for the two child col-6 columns. It is possible that you simply overlooked adding

<div className="crud-footer row">
from your existing CSS framework.

Answer №2

To achieve the desired layout, adjust the justify-content property on your container. Choose between flex-start or space-between based on the layout you want to create.

Take a look at: https://www.w3schools.com/cssref/css3_pr_justify-content.asp

Ensure that your container has enough space to accommodate both elements. You can use width: 100% as an example.

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

Occasionally, the script tags in Next.js fail to load

https://i.stack.imgur.com/tSrIu.png An error message appears when the script tag fails to load. I have a total of 6 script tags in my code. These scripts are present in my code, but they do not consistently load. However, I can see them when ins ...

Could you assist me in retrieving information from an API request?

I can't seem to pinpoint my mistake, but I know it's there. After the user provides their state and city information and submits it, a fetch request is supposed to retrieve latitude and longitude values. These values are then used in another API ...

Getting the submit button to be positioned above the open keyboard in React Native

On one screen, we have two View components within another View. I styled it so that the button is at the bottom. When we click on the input text, the keyboard opens up and the screen adjusts to show the input text properly. However, the submit button rem ...

What is the most effective method for closing a DropDown when a Link is clicked in React?

Here is the code snippet I am working with: Link to Sandbox import React, { useState } from "react"; import ReactDOM from "react-dom"; import { BrowserRouter, Route, Switch, Link } from "react-router-dom"; import "./styles.css"; function DropDown({ close ...

Do remote resource links remain accessible when there is no connection to the internet?

I have incorporated remote resources such as jQuery and icons by linking them like this: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <script src="https://ajax.googleapis.com/a ...

What is the best way to incorporate a sidebar menu in an HTML webpage?

I am interested in creating a sidebar menu for my website using either HTML, CSS, or JavaScript. The W3 Schools website has a side menu that I find appealing and would like to create something similar. ...

Creating a sticky navigation bar in a CSS Grid layout

Using a grid for the first time and attempting to make the nav-bar sticky, I initially used: position: sticky; top: 0; without any success. Subsequently, trying: position: fixed; resulted in undesired consequences. Desiring the nav-bar ...

Fluid active tabs are causing alignment issues with CSS triangles

I have included CSS triangles on the active tabs with fluid width on this page, but they are not aligned properly in each tab. For example, the About Us tab is correctly and centrally aligned, but the others are too far to the right. The issue lies with t ...

What is the relationship between font size adjustments and the dimensions of the surrounding parent div element?

I've come across an issue that involves having the following code snippet in the body of an HTML file: html, body { width: 99%; height: 99%; margin: 0px; overflow: hidden; } #container1 { display: flex; gap: 2%; width: 90%; heigh ...

Keyframe Essentials: Lesson 5 Checkpoint 16 at the General Assembly

As a newbie to coding, I find myself struggling at project 5 checkpoint 16. The task at hand is to define a keyframe that makes the robot's eyes blink, but I can't seem to figure out where I'm going wrong with my syntax. @keyframes blink { ...

Issue with mix-blend-mode causing text to not show up on top of the gradient

I am struggling to find a way to make text easily readable over my gradient background. Despite trying to use MUI's Typography or a simple <p>, the contrast isn't great as the text appears in black. After some research, I discovered that I ...

Ways to conceal a React component when route transitions occur

I am currently utilizing the location prop from react router dom to set my state to false and only render a component if it's true. Below is an example of how I achieve this in React: const [ showFilter, setShowFilter ] = useState(false); const locati ...

Variables for Angular Material themes

My app has multiple theme files, and I select the theme during runtime. .client1-theme{ // @include angular-material-theme($client1-theme); @include all-component-colors($client1-theme); @include theme-color-grabber($client1-theme, $client1-a ...

What could be causing the issue with my HTML drop down menu links not functioning properly

I'm a novice in the world of web design. I recently crafted two drop-down menus for my website, one for projects and the other for labs. While the drop-down functionality itself is operational and the links are clickable, they fail to redirect users t ...

Stopping autoplay in Swiper JS in React when the mouse enters and starting it again when the mouse leaves - a guide

I am currently exploring swiper.js in react by creating a basic image slider with autoplay feature, but I'm unsure how to pause autoplay when the mouse enters and resume it when it leaves. I attempted using onMouseLeave={Swiper.autoplay.stop}, however ...

Verify the input field and redirect it to a different input field using ReactJS

In the process of developing a React application, I initially included a mobile number input field with validation that is currently functioning correctly. Now, my aim is to modify the input field to accept passwords without altering any other form detail ...

Extracting information from a JSON file using React.js

I have a JSON file named data.json in my React.js project: [{"id": 1,"title": "Child Bride"}, {"id": 2, "title": "Last Time I Committed Suicide, The"}, {"id": 3, "title": "Jerry Seinfeld: 'I'm Telling You for the Last Time'"}, {"id": 4, ...

Adaptable background image - smoothly resize/reposition

Is there a way to smoothly resize my background image instead of it jumping abruptly? Currently, when using media queries, the background image goes from 900px to 300px in height instantly at a certain point. How can I make this transition more gradual? ...

Is there a way to update a photo only after a change has been submitted and not during the change process?

My goal is to enable users to have a default profile picture when they log in, with the option to update it later on. I've made progress on about 95% of the functionality but I'm facing a hurdle in the final step. This is how the process unfold ...

After clicking, I would like the text from the list item to have a style of "background-color: aqua" when displayed in the textarea

Is there a way to apply a highlight with a style of "background-color: aqua" in the textarea only to the word selected from the list above after clicking on it? See below for my HTML: <head> <script src="https://ajax.googleapis.com/ajax/libs/ ...