Ways to personalize the md breakpoint for an individual Material UI Grid component with custom CSS

I have incorporated material ui's Grid for responsive user interface design.

<Grid spacing={2} xs={12} container={true}>
  <Grid item={true} lg={4} md={6} sm={12}>...</Grid>
  <Grid item={true} lg={4} md={6} sm={12}>...</Grid>
  <Grid item={true} lg={4} md={6} sm={12}>...</Grid>
</Grid>

In this specific instance, I wish to customize the screen width for the breakpoint md to a value of npx, without affecting other parts of the application.

I have found solutions for adjusting screen width globally across the app and also for individual grid instances using styles.

const styles = theme => ({
  root: {
    [theme.breakpoints.up('md')]: {
      width: npx,
    },
  },
});

However, I would prefer to achieve this customization using CSS instead of material ui styles. How can I accomplish that?

Answer №1

To begin, include the class your-class in each item. Then apply this css:


@media (min-width:960px) { //adjust min-width to your specified value
  .MuiGrid-grid-md-6.your-class {
    flex-grow: 0;
    max-width: 50%;
    flex-basis: 50%;
  }
}

This setup is effective for a new breakpoint of < 960px. If it exceeds > 960px, you will also require:


@media (min-width:600px) and (max-width:959px) { //modify max-width to (your specified value - 1)
  .MuiGrid-grid-sm-12.your-class {
    flex-grow: 0;
    max-width: 100%;
    flex-basis: 100%;
  }
}

The same logic applies to other breakpoints. For instance, with lg where the default breakpoint is at 1280px:

@media (min-width:1280px) {//adjust min-width to your chosen value
  .MuiGrid-grid-lg-4.your-class {
    flex-grow: 0;
    max-width: 33.333333%;
    flex-basis: 33.333333%;
  }
}

// If breakpoint > 1280px, also include

@media (min-width:960px) and (max-width:1279px) { //modify max-width to (your selected value - 1)
  .MuiGrid-grid-md-6.your-class {
    flex-grow: 0;
    max-width: 50%;
    flex-basis: 50%;
  }
}

Further customization will depend on the values you specify, such as lg={4} versus lg={3}... The complete css definitions for MuiGrid can be found here.

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

Troubleshooting Autocomplete User Interface Problems

I am currently working on a website user interface and I have encountered an issue specifically in IE7. When searching for a company, the display is not showing up correctly, as demonstrated in the image below. This problem only occurs in IE7, it works fi ...

What is the best way to make my button sticky across different screen sizes on my webpage?

I'm having trouble figuring out how to make my purple button sticky and responsive on the right side of the screen as I scroll down. Can someone help me with this? This is the snippet of my HTML code: <Col className="colPre"> ...

The span exits the external div only once the animation has concluded

I utilized jQuery to create an animation effect: http://jsfiddle.net/rxCDU/ UPDATE: Please note that this effect is optimized for Chrome browsers! The animation works correctly, however, the green SPAN element moves out of the red DIV only after the ani ...

The object might be undefined; TypeScript; Object

Why is it that the object may be undefined, even though it is hard-coded in my file as a constant that never changes? I've tried using ts-ignore without success. const expressConfig = { app: { PORT: 3000, standardResponse: `Server ...

Tips for incorporating a custom CSS design into a jQueryUI tooltip

I am struggling to apply my custom CSS class on top of the jQueryUI tooltip. Although the tooltip is displaying correctly, my styles are not being applied. Here is the code I'm using: $(document).ready(function () { $("#roles").tooltip({ content: ...

npm is having trouble locating the material-ui module despite it being installed properly

After following the instructions on the material-ui website, I successfully installed the package by running: npm install @mui/material @emotion/react @emotion/styled To confirm that the module was installed correctly, I used npm ls: npm ls <a href="/c ...

Customizing pressed row styles and properties within a map iteration in React Native

How can I modify the style of a single item in a list when a button is pressed in React-Native? I want only the pressed item to change, not the entire row. Here is my attempt at implementing this: //hooks const [activeStyle, setActiveStyle] = useState( ...

Negatives of utilizing two different UI libraries within a single react project?

I have been contemplating a decision that may be considered unconventional from a technical standpoint. Despite my search efforts, I have not come across any explanation regarding the potential drawbacks of this decision. Imagine creating a React website ...

What is the process for retrieving user data from Postgresql using axios.get when the data is already stored within the database?

Using auth0 for user sign up, my React app automatically retrieves user information upon logging in and sends a POST request with axios to the backend. The user ID is stored in userId and the user information is stored in currUser. However, upon logout and ...

What is the best way to update the color CSS property of an element with jQuery?

Can someone explain to me how to modify CSS using jQuery? I am trying to change the font color of "Valid VIN" to red, but my current code doesn't seem to be working: $("#result").html(<font color="red">"Valid VIN"</font>); ...

Having trouble with implementing the signIn function of NextAuth.js server-side and cannot seem to get the redirect working. Need

Currently working on incorporating NextAuth.js into a React JS / Next JS project. The versions I am using are React JS 18.2.0, Next JS 13.0.6, and NextAuth.js 4.18.0. My setup involves server-side rendering with Next API calls deployed on Vercel. To estab ...

Display a hoverable button for a singular element within an array during the process of mapping through the array

const ChatWidget = () => { const bodyRef = useRef(null) const [{messages,roomMessages,roomID,socket,user}, dispatch] = useStateValue() const [dropdown, setDropdown] = useState(false) useEffect(()=>{ const setScreen = () =>{ bodyRef.cur ...

CORS policy blocked Axios React GET request

I am attempting to utilize Axios for fetching an API from in order to receive a response. I am currently facing difficulties in resolving the encountered issue. My Axios call is simple and located in the following file: api/index.js import axios from &q ...

Implementing individual NGRX Selectors for each child component to enable independent firing

My component serves as a widget on a dashboard, and I am using *ngFor to render multiple widgets based on the dashboard's data. Each WidgetComponent receives some of its data via @Input() from the parent. parent <app-widget *ngFor="let widget ...

Is it possible to pass a number instead of a string to Angular's matToolTip within a mat-icon-button? If not, is there a way to convert the number to a string within an Angular

In my current situation, I am facing a challenge with the following line of code: [matTooltip]="ratingId + 1". This line is crucial as it forms part of the arguments for a Material Design button. However, in this case, things are not straightfo ...

Experimenting with a React component that is monitoring states

Consider a scenario where I have a basic React functional component that primarily monitors changes in context and displays a view of the state from that context. export default function Observer(props) { // Utilize a separate dispatch context for perfor ...

adjust the size of the textarea to perfectly fill the available space

I want my textarea within the wrapctxt container to always fill up the remaining space below the wrapctop section, reaching the bottom of the wrapc element. .panelb{ display:grid; grid-template-columns: 130px 34% auto; height:100vh; width: ...

How can you optimize the storage of keys in JS objects?

Just pondering over this scenario: Consider a line definition like the one below, where start and end are both points. let ln = { s: {x:0, y:0}, e: {x:0, y:0}, o: 'vertical' } Now imagine having a vast array of lines, how can we sav ...

Dynamic visual content (map)

I'm currently working on creating an interactive image for my website where clicking on points A, B, C, ... N will reveal bubbles with images and text inside them. Would anyone be able to provide guidance on how to achieve this? Or direct me to resou ...

What are the steps to turn off the rule .MuiInputBase-inputType-121 in Material UI TextField for email input field because of a display problem?

Here is a snippet of JSX code: import TextField from '@material-ui/core/TextField/TextField'; <Col xs={6}> <TextField pattern=".{3,}" name="fullName" ...