Tips for perfectly aligning all elements in a row within a card design

Hi there, I'm trying to figure out how to align the content of this card in a single row instead of stacked on top of each other. Here's the code snippet:

<div class="container">
            <form onSubmit={submitHandler}>
                <div class="row" style={{ width: "300px", marginTop: "40px", marginLeft: "70px", height: "450px" }}>
                    <FormControl variant="outlined">
                        <InputLabel id="demo-simple-select-outlined-label" >Choose Module Type</InputLabel>
                        <Select style={{ marginBottom:"20px"}}
                            name="name"
                            labelId="demo-simple-select-outlined-label"
                            id="demo-simple-select-outlined"
                            onChange={handleDropdownChange}
                            label="TypeList"
                        >
                            {
                                dropdown.map(options =>
                                    <MenuItem value={options["moduleType"]} >{options["moduleType"]}</MenuItem>
                                )}
                        </Select>
                        <TextField 
                            style={{ marginTop: "10px", marginBottom:"20px" }}
                            id="outlined-helperText"
                            label="Module Name"
                            onChange={handleChangeModuleName}
                            variant="outlined"
                        />
                        <TextField
                            style={{ marginTop: "20px" }}
                            id="outlined-helperText"
                            label="Course Duration"
                            onChange={handleChangeDuration}
                            variant="outlined"
                        />
                        <div style={{ margin: "auto", marginTop: "20px" }}>
                        <Button type="submit" variant="contained" color="primary">ADD</Button>
                      </div>
                    </FormControl>
                </div>
            </form>
         </div>

I'd appreciate any help or tips on how to achieve this layout. Thank you :)

Answer №1

The concept of flex containers is to either expand items to occupy available free space or shrink them to prevent overflow. One key feature of flexbox layout is its direction-agnostic nature, unlike traditional layouts such as block (vertically-based) and inline (horizontally-based).

Consider using display: flex; to keep all items in a row.

.row {
    display: flex;
}

Answer №2

Experiment with incorporating the flex property into your design. To do this in your css stylesheet, include the following code:

.row {
    display: flex;
}

It is recommended to avoid inline styles (where you apply css properties directly within your html file). Instead, utilize an external stylesheet (such as style.css). Link it to your html file by adding this line of code:

<link rel="stylesheet" type="text/css" href="/style.css">

Answer №3

To make your row class flexbox enabled, just include display:'flex' in the CSS

.row{
     display:'flex'
 }

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

Receive the button click event outside of the canvas

Is there a way to have separate click events for the button and the ListItem? My focus is on the button click event only, without triggering the ListItem event. Live DEMO import React from "react"; import ReactDOM from "react-dom"; import ListItem from ...

Ensure accurate detection of invalid values for SVG Elements in React using jest testing framework

When testing my react app, I am attempting to capture any errors that are thrown or logged to the console. If a regular HTML element such as <p> contains invalid attributes like <p color={false}></p>, react will display an error via cons ...

Customizing the date-select widths: A step-by-step guide

I've been struggling with adjusting the width of different instances of this line: <%= f.date_select :deadline, :order => [:month, :day, :year], class: 'date-pick', id: 'goal' %> Despite creating unique ids for select, d ...

Vue is actively eliminating a background image through the use of the style attribute

There appears to be an issue where Vue is removing both the style attribute and the background image from this tag. <section style="background: url(images/banners/profiles/profile-banner-1.png);" class="profile-banner flex items-end md:items-end md:j ...

Activate the Alert (https://material-ui.com/components/alert/#alert) starting from the React component at the bottom of the hierarchy

When it comes to alerts, a normal alert is typically used like alert("message to be displayed");. However, I prefer using material UI Alerts which return a JSX component. For example: <Alert severity="success">This is a success alert — check it out ...

How can ReactJS and Python share information with each other?

I am currently developing an application that requires data communication between ReactJS and Python. My primary focus right now is on the React part of the communication. Initially, I thought about using JSON for data exchange but found it challenging t ...

What could be causing my JavaScript code to not function properly in an HTML document?

Hello, I am a beginner in the world of coding and currently delving into web development. Recently, I was following a tutorial on creating a hamburger menu but I seem to be encountering some issues with the JavaScript code. I have double-checked my Visual ...

How can you ensure your CSS code is functional across various browsers?

I have been exploring CSS and HTML for about a week now, but I am facing a challenge that has me stuck for the past thirty minutes. The issue lies in adapting this code to work smoothly across different browsers. While it aligns images in a row of four per ...

Troubleshooting Problems with Adjusting Left Margin Using JQuery

function adjust_width() { $('#cont').toggle(function(){ $('#cont').animate({marginLeft:'0%'}); },function(){ $('#cont').animate({marginLeft:'18.4%'}); }); } The code above is in ...

Is it possible to utilize the Session Object and Session ID for authentication in REST API and RectJS?

We are looking to transition our current web application (which relies on an HTTP API) to a REST service model with ReactJS for the frontend. In our current setup, we heavily rely on the Session object to store and process data. Will it be feasible to co ...

What's the best way to refactor the `await nextEvent(element, 'mousemove')` pattern in my code once it is no longer necessary?

Within my React component, the code includes the following: class MyComponent extends React.Component { // ... trackStats = false componentDidMount() { this.monitorActivity() } componentWillUnmount() { this.trackStat ...

Eliminating and restoring the background in a form field when it is in focus

/* This function clears the default text in a field when clicked on */ $('#edit-field-activity-notes-und-0-value') .each(function() { $(this).data('default', this.value); var mybackground = $(this).css('backgroun ...

filtering a second list by manipulating the first list's state and triggering a method with the help of checkboxes

Dear moderators, I would like to address an ongoing query that is a continuation of a previous question. You can find the original question here. Although I initially attempted to edit the original question, it became necessary to rewrite most of it, so p ...

Having trouble with npm start causing webpack issues?

I have a small React mini app that I am trying to start with the command npm start - package.json - "scripts": { "start": "node server.js" Everything works fine on Windows, but when I try to start it on Ubuntu, the console throws an error. /var/www/r ...

Personalizing antd Styles or CSS for a create-react-app

Currently, I am utilizing create-react-app as my starter kit and decided to experiment with the antd component library. However, I am struggling to customize their styles for branding purposes. Surprisingly, the documentation lacks clear instructions on ho ...

AngularJS fetches the 'compiled HTML'

If I have this angularjs DOM structure <div ng-init="isRed = true" ng-class="{'red': isRed == true, 'black': isRed == false}"> ... content </div> How can I obtain the 'compiled' version of this on a cl ...

Double dragenter events triggered before dragleave in HTML5 drag and drop functionality

Currently, I'm researching HTML5 Drag and Drop functionality by using this resource. However, I've encountered an issue with the dragenter event that seems to fire twice for child elements before the dragleave event. Because of this, the dashed b ...

Unexpectedly, the React custom component is failing to render as intended

I am anticipating the text "SMALL Medium, Big" to be displayed on the screen but unfortunately it's not showing up function Box(prop){ const ele = <div className={prop.cn}> </div> return ele } ...

Issues with Passing Props for Mutation and Query Components- OR -Mutations and Queries

Whenever my handler is triggered, an error pops up stating that the mutation is not a function. Strangely, I noticed that my mutation and query are not being linked to my component when I check this.props. ERROR: RelationshipDropDown.js:58 Uncaught Type ...

Accessing a New Router with ReactJS

Within my navigation bar, I have implemented an AppRouter using the material-ui library. <NavigationBar> <AppRouter/> </NavigationBar> The structure of my AppRouter is as follows: <Switch> <PublicRoute path="/" compon ...