Struggling to replicate Bootstrap's col-md-6 with Tailwind CSS in React?

How can I make my box/form appear in the center of the screen with its width filling half or all of the screen? I've attempted using the w-full class on different elements but haven't been successful in adjusting the width.

I am working with react, and below is my component code:

import React from 'react';
import { LockClosedIcon } from '@heroicons/react/solid';

function App() {
    return (
        <div>
            <div className="flex h-screen">
                <div className="m-auto">
                    <div className="shadow font-medium bg-white rounded-md flex p-10 pt-4 items-center justify-center w-max">
                        <form className="space-y-6" action="#" method="POST">
                            <input type="hidden" name="remember" defaultValue="true" />
                            <div className="rounded-md shadow-sm -space-y-px">
                                <div>
                                    <label htmlFor="email-address" className="sr-only">
                                        Email address
                                    </label>
                                    <input
                                        id="email-address"
                                        name="email"
                                        type="email"
                                        autoComplete="email"
                                        required
                                        className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
                                        placeholder="Email address"
                                    />
                                </div>
                                <div>
                                    <label htmlFor="password" className="sr-only">
                                        Password
                                    </label>
                                    <input
                                        id="password"
                                        name="password"
                                        type="password"
                                        autoComplete="current-password"
                                        required
                                        className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-b-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
                                        placeholder="Password"
                                    />
                                </div>
                            </div>
                            <div className="flex items-center justify-between">
                                <div className="flex items-center">
                                    <input
                                        id="remember-me"
                                        name="remember-me"
                                        type="checkbox"
                                        className="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded"
                                    />
                                </div>
                                <div className="text-sm">
                                    <a href="#" className="font-medium text-indigo-600 hover:text-indigo-500">
                                        Forgot your password?
                                    </a>
                                </div>
                            </div>
                            <div>
                                <button
                                    type="submit"
                                    className="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
                                >
                  <span className="absolute left-0 inset-y-0 flex items-center pl-3">
                    <LockClosedIcon className="h-5 w-5 text-indigo-500 group-hover:text-indigo-400" aria-hidden="true" />
                  </span>
                                    Sign in
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    );
}

export default App;

Answer №1

At the beginning of your JSX code, I believe there are a couple of adjustments that need to be implemented:

  • Adjust the width of the 3rd div to your preferred size. The md:w-1/2 class behaves similarly to col-md-6 in Bootstrap.
  • Delete the w-max class from the 4th div as it restricts the width of that element to its content. Perhaps w-full is what you intended, but it may not be necessary once the width of the parent element is set.

Below is the updated JSX code with these modifications:

<div>
    <div className="flex h-screen">
        <div className="m-auto md:w-1/2">
            <div className="shadow font-medium bg-white rounded-md flex p-10 pt-4 items-center justify-center">
                {/* ... */}
            </div>
        </div>
    </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

Is there a way to slow down the falling effect on my navigation bar?

As I was working on my personal website, I had a creative idea to add a falling-down animated effect instead of keeping the layout fixed. Utilizing bootstrap for navigation, I encountered some difficulty in controlling the speed of the falling effect. Any ...

Creating overlapping layouts with absolute positioning in Bootstrap leads to a visually appealing

I'm currently working on a layout that involves absolute positioning elements, similar to the one shown in this example: https://i.sstatic.net/TixbZ.jpg It seems like the elements are overlapping and not clearing properly. I've been looking for ...

Expanding the axes using Google Charts

Seeking to Expand Y-Axis I am attempting to stretch the Y-axis so that it counts up to 300 instead of just 100. The issue arises when I adjust the Y-axis to reach 300, as the values remain in the same position as they did when counting to 100. Fo ...

What sets npm install -g react-native-cli apart from utilizing npx react-native init <project name>?

**Can you explain the difference between setting up react-native-cli with npm install -g react-native-cli and init as opposed to using npx react-native init? As I was developing a React Native app, I encountered some strange errors. Initially, I set up m ...

Issue with the close button formatting in the React Bootstrap 4 modal window

In my quest to create a modal window in ReactJS using Bootstrap 4, I encountered an issue with CSS formatting for the close button. Interestingly, Bootstrap 3 worked fine with the CSS. You can check out my code here. Any advice would be greatly apprecia ...

Removing HTML tags from a React UL/LI component can be achieved by using regular

I am currently facing an issue with displaying a ul populated with lis in React on the DOM. The problem is that they are showing the HTML markup along with the content. https://i.sstatic.net/h4fIf.png For example: <strong>Wattage:</strong> 11 ...

Tips for integrating a custom handler to the close icon in Material UI TextField component

In my Reactjs/Typescript project using Material UI, I have a search input component rendered with TextField. The built-in "x" icon clears the input value, but I want to create a custom handler for making an API call when the search value is deleted. I&apo ...

Is there a way to implement a scrollbar within a DIV element?

I'm working on a webpage that includes several customized buttons within multiple DIVs. Take a look at this example on the fiddle. Since I have a lot of buttons, I need to find a way to add a scrollbar so users can easily navigate to the desired butt ...

The Bootstrap container is extending beyond the boundaries of the page view

Since I'm not a CSS enthusiast, I opted to incorporate Bootstrap into my small project. However, I've encountered an issue where one of the containers is extending beyond the page view, and I can't seem to figure out why. <!-- STYLE ...

What is the best way to apply an animation class to a modal upon clicking a button?

When I click the "x" button on the modal, I want the animation to occur. However, what currently happens is that the modal closes without the animation. Then, upon reopening the modal, the animation occurs without any clicking involved. Below is my curren ...

The navbar background spans the full width of the screen, with all content contained within minimum and maximum width parameters

Currently, I am working on a fluid website design where I have set specific min-width and max-width values. However, I want the navigation bar background to extend across the entire screen width without being limited by the max width parameter, while still ...

Issue with Bootstrap small column vertical alignment not functioning as expected

I am working on a bootstrap layout with two columns. One column contains multiple elements and text, making it quite long, while the other column only has an image. I am trying to center this image vertically within the left column of content. Here is the ...

Tips for executing an asynchronous fetch prior to the first rendering

Currently, I am working with the Wordpress API using Next.js on the front end. My goal is to fetch my navigation/menu data and have it pre-rendered. However, my attempts have only resulted in an empty <nav> </nav> element being rendered when I ...

What is the reason behind Drupal 8 appending a GET variable to the end of each CSS file and resulting in a 404 error?

I've been struggling for hours trying to figure out why the CSS is not loading on the Drupal 8 site I'm migrating. Despite successfully resolving other issues, the CSS files are throwing a 404 error, specifically due to a GET variable (?oe62rp) a ...

Issues with Jquery Div sliding transitions from right to left are not functioning correctly

Creating page transitions in jQuery similar to "http://support.microsoft.com/." Encountering an issue where after the page transitions are completed, they start from the left instead of the expected right direction. Referencing this fiddle (Working Code) ...

The React/MUI theme seems to be behaving inconsistently across various components

As a first-time user of React/MUI, I am struggling to implement themes consistently. Let me illustrate my issue with a simple example featuring a Box component: import { createTheme, ThemeProvider } from '@mui/material/styles'; import Box from &a ...

Restoring an image to its initial position with React-Draggable

I am facing an issue with returning an image to its original position after a drop. The image is located inside a Popover and I'm using the React-Draggable library (https://github.com/mzabriskie/react-draggable) to move it around as part of an insert ...

Troubleshooting file upload issues in API Platform and React

I am trying to upload an image to my API using React, FormData, and Axios, but for some reason, the request in my custom controller is returning null. Interestingly, the API accepts the image perfectly when I use Postman. When I include a boundary in the ...

The nextjs API route handler is experiencing an issue due to the absence of the Prisma Post request

Encountering a problem while sending a JSON content post request to Next.js API route handlers using Thunder Client. { "category_name": "Category Name" } Getting a 500 Internal Server Error when making a POST request via Thunder Clie ...

I'm having trouble centering divs with Bootstrap

Currently, I am utilizing MVC5 with the Razor view engine and Bootstrap. I am facing an issue where I am trying to center some images, but I am running into difficulties. Oddly enough, when I include the Bootstrap.css file, the centering does not work as ...