Tips for fixing padding problems in mobile view mode

My grid-template-columns currently has 4 columns, but I want it to have only 1 column on mobile devices.

This is my CSS setup:

<div style={{ padding: 16 }}>
  <div className={styles.cardContainer}>
    {data.map((value, index) => <div key={index} className={styles.card} />)}
  </div>
</div>

CSS:

.cardContainer {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(364px, 1fr));
  gap: 2rem;
  width: 100%;
  background-color: pink;
  @media (min-width: 1200px) {
    grid-template-columns: repeat(4, 1fr);
  }
}
.card {
  min-height: 522px;
  box-sizing: border-box;
  border: 1px solid $color-neutral-30;
  background-color: $color-neutral-10;
  border-radius: 24px;
  padding: 16px;
  width: 100%;
}

It's functioning properly on desktop, but there is a padding-right issue on certain mobile devices.

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

The padding-right should be 16px, how can this issue be resolved?

Answer №1

.containerCards {
  display: grid;
  gap: 2rem;
  width: 100%;
  background-color: pink;
}

.cardStyle {
  min-height: 522px;
  box-sizing: border-box;
  border: 1px solid $color-neutral-30;
  background-color: $color-neutral-10;
  border-radius: 24px;
  padding: 16px;
  width: 100%;
}

@media (min-width: 576px) {
  /* Adjust layout for small mobile landscape */
  .containerCards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 768px) {
  /* Adjust layout for tablets */
  .containerCards {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 992px) {
  /* Adjust layout for larger tablets and desktops */
  .containerCards {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Add more media queries as needed */

Important: This CSS code sets up a responsive grid layout for cards, with the number of columns adjusting based on screen size. It's crucial to use media queries effectively to ensure proper display on various devices.

Make sure to customize the breakpoints and column numbers to fit your design needs. By utilizing media queries, you can create an adaptable grid layout that addresses padding issues on mobile screens.

#styling #webdesign

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

Leaflet.js in Internet Explorer 11: The tile images are present in the DOM but are not showing up on the

I have been using leaflet to display construction plans for our software, specifically as jpg tiles. For the past 9 months, this has been working smoothly on browsers such as IE11, Firefox, Chrome, and Safari. However, starting from yesterday, I am encount ...

What is the reason for forEach returning an empty array?

I am currently working with an array called getOrdersBySalesman which holds information about orders, such as id, client, and stage. My goal is to filter these orders based on their stage attribute, however, I seem to be encountering an issue where the c ...

Need to style today's date and selected date differently using react datepicker

I am currently working with the React Datepicker and I am facing an issue where two different styles need to be applied for the current date and a selected date. Specifically, I have defined a style for the current date as well as a separate style for whe ...

Swap the contents of a list with a corresponding image

Having trouble replacing text (link) inside a list with an image. Can't seem to get it working Here's my code: HTML: <div id = "headeranna"> <ul> <li><a href="#" id="annaklein">Ask Anna</a></li> ...

What happens when browsers encounter unfamiliar at-rules?

CSS at-rules have been part of CSS since the days of CSS2. As CSS evolves with new specifications like @supports, it's interesting to see how different browsers handle unsupported rules. Do major browsers simply ignore unrecognized rules, or do they f ...

What is the best approach to establish the right 'this' Lexical Scope while utilizing Promises in ES6/React?

I've been exploring the use of the FourSquare API to retrieve location data within my React App. To achieve this, I'm leveraging a convenient package available here: https://www.npmjs.com/package/foursquarevenues The package employs promises to ...

What is the best way to eliminate the border around the input beneath the li element

I am trying to create a language tab input like this: https://i.sstatic.net/N0h2o.png But I want it to look like this: https://i.sstatic.net/QmnSr.png However, I am facing an issue with the border when any language tab is active! Here is my code in En ...

Utilizing HTML types in a custom hook with React and Typescript

Is it possible to pass type annotations like as SVGElement or as HTMLDivElement into a hook? function AppSVG(){ const ref = useResizeObserver((entry) => { ... }) as SVGElement;// <- How can the SVGElement be passed to the hook? r ...

Is it possible to customize my selectbox by adding a logo to each item in the dropdown menu?

Looking to customize my select box with app logos next to the options. Any suggestions or tips would be greatly appreciated! ❤️ <select class="selectdiv2" id="selection2" name="platform" required> <option valu ...

The auto-fill feature in Chrome mistakenly inputs the saved username in the wrong field

My web application, coded in HTML/PHP with a login screen, is encountering an issue with Chrome users. After logging in and navigating to the home page, some users are prompted to save their password. This leads to the username appearing in a field unrelat ...

Applying CSS to multiple divs following the execution of forEach() on an array of objects

MyArray consists of an array of objects. By using forEach(), I am able to retrieve the individual objects from it. However, I have encountered an issue where the text from each object is being displayed on top of each other on the page. Is there a way fo ...

Enhancing Next.js Images with Custom CSS Styles

I am working with a Next.js component: import styles from '../styles/Navbar.module.css' import Image from 'next/image' export const Navbar = () => { <div> <Image className={styles["navbar-home-icon"]} ...

invoke a method within ActionState utilizing a parameter in Nextjs

I am looking to implement the use of the ActioState hook in my remove button handler function: const RemoveButton = ({ task }: { task: Task }) => { const [state, handleRemoveTask, ispending] = useActionState(removeTask, { message: " ...

What is the best way to center align two inner divs within a container?

I've been working on achieving the following design: https://i.sstatic.net/ckC3j.png Just to clarify, the dashed line represents a guide indicating that both .inner-a and .inner-b are aligned in the middle horizontally and vertically within the imag ...

Photo on vertical display

I have been working on displaying dynamic photos from a backend file and looping through them. I have successfully displayed the images vertically using CSS. vertical-align: middle; However, when I tried to add a photo name for each image, the positionin ...

Typography Multiline Button

Having trouble creating a multi-line Button with Material-UI in React. Here's the code I'm using: <Button> <Typography variant="h3">Text1</Typography> <Typography variant="h5">Text2</Typography> ...

Retrieve all true and false values that have been checked or unchecked in an array using jQuery AJAX, and send them to a Laravel controller

How can I set a default value of false for a checkbox, and when it is checked, display true with its name like: ("user_management_create":true). Also, upon form submission, if no checkbox is checked, provide a false value as well like ("User_management_eri ...

Included adaptable background-images in the upload

Recently, I developed a RoR based app/website that allows clients to upload their own background image to the cover page. Although the current setup works well with a single image, I am aiming to enhance the site's responsiveness by enabling clients t ...

Express JS res.send() with an array response data is posing a concern during the Checkmarx scan

When using the axios library in my express middleware to retrieve responses from APIs, I encountered a security concern raised by Checkmarx scan report. router.post(someurl,req,res) { axios .get(someurl) .then((response=>{ **res.send(response.data);**/ ...

Customize which days are enabled in the DatePicker

I'm in the process of developing a website with Office Fabric UI, but I haven't been able to figure out how to selectively enable specific days on the DatePicker component while disabling all others. My technology stack includes Nodejs and React ...