Why is the Material UI React select not selecting all children except for the last one?

I have a challenge with selecting specific children:

const useStyles = makeStyles(theme => ({
  icons: {
    "&>*": {
      backgroundColor: "red",
    },
  },
}))

This is how it looks in JSX:

    <Grid item>
      <Grid container direction="column" classes={{ root: classes.icons }}>
        <Grid item>
          <img src={facebook} alt="facebook" />
        </Grid>
        <Grid item>
          <img src={twitter} alt="twitter" />
        </Grid>
        <Grid item>
          <img src={instagram} alt="instagram" />
        </Grid>
      </Grid>
    </Grid>

However, I encountered an issue when trying to select all children except the last one:

 icons: {
    "&:not(:last-child)": {
      backgroundColor: "red",
    },
  },

I would appreciate any help on what I might be missing. Thank you!

Answer №1

I successfully implemented the solution using sx to achieve your desired outcome.

const gridStyles = {
  "& >*": {
    backgroundColor: "green"
  },
  "& :not(:last-of-type)": {
    backgroundColor: "red"
  }
};
...
<Grid container direction="column" sx={gridStyles}>...

You can view the sandbox example here: sandbox

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 showcase the outcome of a Python script on an HTML webpage?

Hey there, I'm a beginner to coding and I've been working on a little project to track the price of gold in a web application using Flask and Python. In my HTML code, I have a button that, when clicked, takes users to a new route where the gold ...

Performing asynchronous operations in React with axios using loops

On the backend, I have a socket set up to handle continuous requests from the server. Now, my goal is to send requests to the backend API continuously until a stop button is clicked. Using a loop for this task is considered bad practice as it never checks ...

Ways to update the color of the mat-dialog-title using the material theme

Currently, I am utilizing the Angular Material Dialog and have been attempting to dynamically change the title color of the dialog based on the material theme. <h1 mat-dialog-title color="primary">{{ title }}</h1> Even though setting ...

Determine the quantity of items that meet specific criteria

The initial state of my store is set as follows: let initialState = { items: [], itemsCount: 0, completedCount: 0 }; Whenever I dispatch an action with the type ADD_ITEM, a new item gets added to the items array while also incrementing the count in ...

Is the Bootstrap carousel sliding to the top after clicking the next and previous buttons?

Here is the carousel I created using Bootstrap: <div id="carouselExample" class="carousel slide d-none d-sm-none d-md-block" data-ride="carousel"> <div class="carousel-inner"> <div class="carousel-item active ...

Hover over the text below to see an image appear in its place

I'm looking to swap out some text with an image when hovering over it, using basic HTML/CSS. NO: show the image below the text NO: display the text on top of the image NO: replace one image with another YES: replace the text with an image ...

Combining CSR and SSR in the next iteration of our project will

In my application, I have three main user roles: Consumer, Merchant, and Admin. I want the pages that Consumers access to be SEO friendly and server rendered. However, for Merchants and Admins, I prefer them to be client rendered with their own respective ...

What is the best way to transform URL images on a webpage into media library images in WordPress?

Having trouble converting HTML Static Sites to WordPress because images are hosted through HTML SRC Code. After conversion, no one can see the images in visual format on pages during editing. Is there a way to convert all image links inside pages to media ...

Scrollable navigation bar at the bottom styled with Bootstrap

I've been trying to find an answer to this question online but haven't had any luck. I designed a responsive bottom navbar with Bootstrap, but I'm encountering an issue when listing multiple items using the <li> tag - it creates a new ...

What modifications were implemented in Bootstrap 5 to cause controls to automatically assume their maximum size?

After upgrading NodeJs to version 16.13.0 from 14.x, one of the modules that was updated was bootstrap. This caused me to remove my Jumbotron control due to the upgrade, although I don't believe that is directly related to the issue I am experiencing. ...

Encountering a problem when trying to launch the React application

I encountered an error while running the "npm start" command after creating a React app using npx create-react-app my-app. 0 info it worked if it ends with ok 1 verbose cli [ 1 verbose cli 'C:\\Program Files\\nodejs\\ ...

The react-datepicker component is unable to set the state to the format dd/MM/yy

The date is currently shown in the correct format (31/08/21), but when onChange gets triggered, startDate changes to something like this: Tue Aug 31 2021 21:29:17 GMT+0200 (Central European Summer Time) Is there a way to maintain the display format I wa ...

sending axios request, parsing error object to extract validation message

When I send an axios put request, I keep getting a status code 400 error. The server sends a user-friendly validation error message which shows up in the dev tools as https://i.sstatic.net/Pdxsx.png In my catch block, I expect to retrieve the error messa ...

Is there a way to create a dropdown menu that appears to emerge from behind a button?

I am struggling with the stack order of my dropdown menu. Despite using z-index, it appears in front of the button instead of behind it. I want it to look like it is coming out from behind the button. Here is my code: .subnav-wrapper { position: relat ...

Efficient method for deleting a specific item from a JSON object in React.js

Within the REACT JS framework, I am managing a JSON object in the state component "myrecords". The items within this object are organized by their respective Company Names and have the following structure: { "Master Automotives": [ { ...

Designing a flawless CSS pattern for the online world

Currently, I am working on creating a seamless CSS pattern for the web. Even though this may seem impractical and nonsensical, I find joy in experimenting with it. View my progress here After successfully designing my first tile, my next challenge is to ...

Mastering the art of gracefully transitioning to a fallback option when CSS grid

When it comes to creating a simple grid of squares (3x3 at most, filling in top to bottom left to right), I have encountered challenges with both flexbox and grid. The DOM structure required for each method seems incompatible or too complex to support both ...

Error: The resource could not be retrieved due to a network issue

After encountering similar issues without finding a solution, I turned to this platform for help. I am new to front-end development with React and have set up separate applications for the front end and backend on different ports. Backend: Laravel framewo ...

The media query in Css3 is not functioning as expected when using max-width

Struggling to hide a specific element when the screen width reaches 980px or less using media queries. Despite my attempts, the element continues to display. Oddly enough, if I use a media query with min-width instead of max-width, the element disappears ...

What steps do I take to eliminate this additional content?

Currently working on a web messenger project and facing an issue with a specific bar that I want to remove from my interface: Within the Home.blade.php file, the code snippet looks like this: @extends('layouts.texter') @section('content&ap ...