Breaking Points in Tailwind are crucial for creating responsive designs

I am attempting to create a simple div where I want px-5 for mobile screens and px-20 for larger screens. However, only px-5 is working and px-20 is not applying on large screens. Can someone help me understand why?

Code Output Image

 <div class="bg-white py-20  px-5  lg:px-20 ">
        <div class="w-full md:w-1/2 mx-auto space-y-8">
          <div class="bg-white py-20 rounded-xl shadow-lg p-6 flex flex-col items-center justify-between">
            <div class="flex flex-col md:flex-row items-center justify-between w-full">
              <div class="flex py-4 flex-col md:flex-row justify-start w-full h-full">
                <div class="flex flex-col lg:ml-10  md:items-start">
                  <h2 class="text-xl md:text-4xl font-semibold mb-2 text-center md:text-left">
                    Lorem ipsum dolor sit
                  </h2>
                  <p class="text-gray-600 text-center md:text-left">
                    Porem ipsum dolor sit amet, consectetur adipiscing elit.
                  </p>
                </div>
              </div>
              <div className="flex flex-col justify-center sm:justify-center lg:justify-end md:flex-row mt-4 md:mt-0 w-full ">
                <input
                  type="text"
                  placeholder="Enter email here"
                  className="lg:w-96 sm:w-1/2 py-2 px-2 sm:px-10 border border-gray-300 rounded-sm focus:outline-none focus:border-indigo-500 transition duration-150 ease-in-out"
                  // Adjust the width here, sm:w-1/2 means the input width will be half of the container on small screens and above
                />
                <button
                  className="mt-3  lg:w-1/3 sm:mt-0 flex items-center justify-center md:ml-4 text-white py-3 px-4 rounded-sm hover:bg-orange-700 focus:outline-none focus:bg-orange-700 transition duration-150 ease-in-out"
                  style={{ backgroundColor: "#F68219" }}
                  // Adjust the width here, sm:w-1/2 means the button width will be half of the container on small screens and above
                >
                  Start E-Filling Now
                  <img src="/arrow.svg" alt="" className="ml-2" />
                </button>
              </div>
            </div>
          </div>
        </div>
      </div>

Expected Result Image

In the second image shown in the link, you can see that I want px-20 to apply on large screens as expected.

Answer №1

To create margins on both the left and right sides of the div, it is recommended to use the margin property instead of padding.

 <div class="bg-white py-20 mx-5 lg:mx-20">

Answer №2

<div className="bg-white py-20  px-5  lg:px-20 ">
  <div className="w-full  mx-auto space-y-8">
    <div className="bg-white py-20 rounded-xl shadow-lg p-6 flex flex-col items-center justify-between lg:mx-20">
      <div className="flex flex-col md:flex-row items-center justify-between w-full">
        <div className="flex py-4 flex-col md:flex-row justify-start w-full h-full">
          <div className="flex flex-col lg:ml-10  md:items-start">
            <h2 className="text-xl md:text-4xl font-semibold mb-2 text-center md:text-left">
              Lorem ipsum dolor sit
            </h2>
            <p className="text-gray-600 text-center md:text-left">
              Porem ipsum dolor sit amet, consectetur adipiscing elit.
            </p>
          </div>
        </div>
        <div className="flex flex-col justify-center sm:justify-center lg:justify-end md:flex-row mt-4 md:mt-0 w-full ">
          <input
            type="text"
            placeholder="Enter email here"
            className="lg:w-96 sm:w-1/2 py-2 px-2 sm:px-10 border border-gray-300 rounded-sm focus:outline-none focus:border-indigo-500 transition duration-150 ease-in-out"
            // Adjust the width here, sm:w-1/2 means the input width will be half of the container on small screens and above
          />
          <button
            className="mt-3  lg:w-1/3 sm:mt-0 flex items-center justify-center md:ml-4 text-white py-3 px-4 rounded-sm hover:bg-orange-700 focus:outline-none focus:bg-orange-700 transition duration-150 ease-in-out"
            style={{ backgroundColor: "#F68219" }}
            // Adjust the width here, sm:w-1/2 means the button width will be half of the container on small screens and above
          >
            Start E-Filling Now
            <img src="/arrow.svg" alt="" className="ml-2" />
          </button>
        </div>
      </div>
    </div>
  </div>
</div>

Inspect this closely because you were utilizing the tailwind utilities improperly in that specific div. To achieve the desired outcome, feel free to make adjustments to this code snippet.

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

react-i18next is throwing a missingKey error only during the build process

https://i.stack.imgur.com/cicuW.png My code includes index.js and i18next.js(the configuration for i18n) index.js import React, { Suspense } from 'react' import i18n from './i18next' import './i18next' import ReactDOM from & ...

The type is lacking the property onAuxClickCapture and onAuxClick

When utilizing forwardRef from React, an unexpected type error occurs: The type '{ children: ReactNode; }' is lacking the properties specified in 'Pick<ILinkProps, "className" | "children" | "accept" | "acceptCharset" | "action" | ... 34 ...

What is the best way to add a line break to a String element in React JS?

Hey, I'm having trouble with something here let ifAID = "Banco: Global Bank\nTipo de Cuenta: Corriente" I need a line break where \n, but it's not working. Any suggestions? https://i.stack.imgur.com/j8fJr.png In my setup, ...

Switch between selection modes in React JS DataGrid using Material UI with the click of a button

I've been working on creating a datagrid that includes a switch button to toggle between simple and multiple selection modes. const dispatch = useDispatch(); const { selectedTransaction } = useSelector(...) const [enableMultipleSelection, setEnableMu ...

Navigating the implementation of undefined returned data in useQuery hook within Apollo and ReactJS

I am facing an issue with my code where the cookieData is rendered as undefined on the initial render and query, causing the query to fail authentication. Is there a way to ensure that the query waits for the response from the cookie API before running? co ...

What are some ways I can improve the readability of this if-else function in Javascript ES6?

As a newcomer to React development, I am currently in the process of tidying up my code. One issue that I am facing is how to deal with a particular function while minimizing the use of if-else statements. const calculatePerPage = () => { if ...

Encountering Excessive Open Files Error with NextJS Deployment

I'm encountering a challenge in my Production environment during peak traffic hours. Any assistance with pinpointing the origin of this issue would be greatly appreciated. Error logs - [Error: EMFILE: too many open files, open '/app/.next/static ...

Encountering an issue with Firebase authentication in Next.js: the window object is not defined

Here is some code snippets: import { initializeApp } from "firebase/app"; import { getAnalytics } from "firebase/analytics"; import { getAuth } from "firebase/auth"; const firebaseConfig = { //credentials// }; export const ...

What is the best way to update the state of a component when a button is clicked in another component?

When the "updates" button in my component is clicked, the application scrolls down to a specific Parent section. This Parent section is displayed on the page by another component and contains a toggle button that shows/hides other child sections within the ...

Tips for creating consistent spacing between elements using Tailwind CSS version 3

I am currently utilizing Tailwind CSS in conjunction with next.js for my project. I have a total of 8 images, each varying in size, and my goal is to display 4 images per row on medium and large devices, while displaying 2 images per row on small devices. ...

The darkTheme setting in Material-UI does not have any impact on the styles of

I have a simple question about utilizing the Material-ui default darkTheme in a specific section of my app. Below is a sample code snippet: <div> <MuiThemeProvider muiTheme={getMuiTheme(darkBaseTheme)}> <div> <AppBar title ...

Tips for effective state management when using both React router and Redux

I am currently working on retrieving data from an API which is stored in a variable called items. { '001': {id: '001', name:'foo',color:'blue' }}, '002': { id: '002',name:'bar',color:&a ...

Converting images to greyscale or transparency within a ReactJS component

I am exploring ways to transform an image into grayscale or make it transparent before using it as a background in ReactJS. Is there a way to achieve this in ReactJS? My current code snippet is shown below: <GridListTile> <img style={{ -we ...

change the width of a div element to match that of its nearest sibling element

Can the width of a div be automatically set to match its closest sibling when the width is set to width: auto;? In my coding example on jsFiddle, you can observe three colored divs - red, green, and blue. I am aiming for the blue div to adjust its size ba ...

Ways to merge two arrays into one in React JS

Here are two arrays presented below: const arrayA = { 0: { id: XXXXXXX, name: "test" }, 1: { id: YYYYYYY, name: "example" } } const arrayB = { 0: { id: XXXXXXX, category: "sea", } 1: { id: YYYYY ...

Changes made to the data are not reflected in the user interface, but they are visible in the console

When working on a React project with input fields, I encountered an issue where the date data can be changed but doesn't get reflected in the UI. Instead, the updated data is visible in the console. The code snippet below showcases how I'm using ...

Step-by-step guide on triggering a button using another button

I have a unique question that sets it apart from others because I am looking to activate the button, not just fire it. Here is my syntax: $("#second_btn").click(function(){ $('#first_btn').addClass('active'); }) #first_btn ...

header color scheme and dimensions

Hello, I've managed to get the menu working correctly on my website at www.g-evo.com/header.php. However, I'm now facing an issue with the size of the header. I'd like to shrink the grey area slightly so it aligns better with the logo, while ...

Tips on showcasing the elements within a div container using flexbox

Seeking advice on positioning items/cards using flexbox in my initial react app. The issue lies with the div within my card component where applying display: flex; turns every card into a block (column-like) structure, flexing only the content within each ...

Error encountered during conversion to Typescript for select event and default value

When trying to set the defaultValue in a Select component, TSlint throws an error - Type 'string' is not assignable to type 'ChangeEvent<HTMLInputElement> | undefined - for the code snippet below: const App = () => { const [ mont ...