Reverse the impact of the preceding CSS directive

In this screenshot example, the padding at the bottom in Material-UI has been increased from 16px to 24px using the CSS rule below:

.MuiCardContent-root:last-child {
    padding-bottom: 24px;
}

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

I want to revert it back to 16px, which was the original value set by a previous rule. How can I achieve this using either Material-UI API or plain CSS?

I attempted the following code but it only changed the value to 0:

const useStyles = makeStyles(function (theme) {
    return {
        // ...
        cardContent: {
            '&:last-child': {
                paddingBottom: 'inherit|initial|revert|unset', // (only one at a time, of course...)
            },
        },
    };
});

// ...
    <CardContent className={classes.cardContent}>
// ...

While I could manually set it to 16px, I prefer not to go with this option for obvious reasons.

Answer №1

While I may not have full knowledge about the MaterialUI elements you're incorporating, one suggestion could be to utilize the unset property. This can instruct the :last-child selector to inherit values from the cascade, such as the default setting of .MuiCardContent-root.

Answer №2

Suppose your requirement is that the last child should not receive special treatment solely based on its last-child status in this scenario, the recommended solution would be to introduce a new class in the HTML markup.

Subsequently, modify the CSS to target only the last child that does not contain that specific class.

This ensures that no unintended changes are applied to similar elements on other pages.

    .materialUI {
        padding-bottom:16px;
        color: #f00000;
    }
    .materialUI:not(.notThisOne):last-child {
         padding-bottom:24px;
         color: #330;
         font-weight:bold;
         font-size:1.5rem;
    }
    <div>
        <div class='materialUI'>
            <p>Hello this is the page you want to edit</p>
        </div>
        <div class='materialUI notThisOne'>
            <p>Horse must not be last childed</p>
        </div>
    
    </div>
    
    
    ----------------------------------

    
    <div>
        <div class='materialUI'>
            <p>Any OtherPage</p>
        </div>
        <div class='materialUI'>
            <p>Other Page Last Child</p>
        </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

I am experiencing difficulties in installing JavaScript libraries

PS D:\React> npm i -g expo-cli npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d48555d42004e41446d68c7b6d717268805a6369786964 ...

Are there any improved methods for optimizing the CSS in my Next.js project?

Currently, I'm immersed in a project using Next.js and styling it with CSS in JS (ReactJSS). Upon inspecting the page source, I noticed that there are over 4000 lines of CSS for a single page, which is not ideal for performance. To provide context, l ...

Dynamic updating in a React application with an express server

Currently, I have set up a boilerplate for a MERN application with an express server on the backend and react on the frontend. My goal is to implement hot reloading in my app so that changes in the react code can be reflected without needing to refresh the ...

The sub-menu options are constantly shifting... How can I keep them in place?

Here we go again... I'm having trouble with my sub-menu elements moving when I hover over them. I've searched for a solution but haven't found anything helpful. The previous advice I received about matching padding and adding transparent bo ...

Customizing Material-ui picker: concealing text field and triggering modal with a button click

I'm currently working with version 3.2.6 of the material-ui pickers library to develop a component that has different renderings for mobile and desktop devices. For desktop, I have set up a standard inline datepicker with a text input field, while fo ...

Is there a way to alter the styling of a React element without resorting to querySelector?

Just diving into React and I'm faced with a challenge - how to update the CSS of a class based on a condition. let customizeColumn = document.querySelector(".main-table-body"); !expandFilter ? customizeColumn.setAttribute("style", ...

Tips for maintaining an open side menu

I'm having trouble keeping the side menu open when a user clicks on one of the child menu items. Ideally, I want section 1 to display section 2 content when hovered over, and keep both sections open even when section 2 is clicked. The only time they s ...

Center the span in CSS by setting its position to absolute

I am trying to create a span element positioned as absolute inside a div. The div has top and left values set. When the user inputs text, the span expands with the given text towards the right to contain it. However, I would like it to grow symmetrically o ...

React JS BlueprintJS Date Range Picker not functioning as expected

I am struggling to implement a DateRangePicker using BlueprintJS on my component, following the instructions in the documentation. I also want to include a RangePicker similar to the one shown in this screenshot. I have successfully installed all the nece ...

Activate secure server (HTTPS) in Create React App by setting the flag in package.json according to the .env

In order to run create react app in SSL mode, the package.json file needs to have HTTPS=true set like this: "start": "HTTPS=true react-scripts start", It is preferred that this setting only apply in production and not locally durin ...

Tips for simulating next/router in vitest for unit testing?

Struggling with creating basic tests for our Next.js application that utilizes the useRouter() hook, encountering errors when using vitest. In search of solutions to mock next/router for unit testing in conjunction with vitest. ...

The useStyles function does not automatically update properties in response to changes in variables

I have encountered an issue where the style of a component is not changing based on a boolean state change until I refresh the page. Here's what I'm doing: Within my parent App component, I have the following code: import React from "react"; imp ...

The React hamburger menu triggers a re-render of child elements within the layout

I am currently working with React and Material UI v5. Within my layout, I have a menu component with children. Whenever I click on the menu, it triggers a refresh of the children components. I attempted to resolve this by encapsulating the child components ...

A duo of adjacent buttons styled with HTML, CSS, and Bootstrap

I'm encountering an issue with the layout of my design. On my product page, I have two buttons placed on top of each other because one is within a form (refer to the image). https://i.sstatic.net/cS9TI.jpg I would like to position the two buttons s ...

Experiencing difficulty in successfully updating a React child component when the prop passed from the parent component is

In the backend implementation, I have successfully set up a socket.io, Node, Express configuration that has been tested to work correctly. It is emitting the right number of broadcasts to the appropriate client using socket.emit("team_set", gameI ...

HTML - Toggle visibility of div using display property

I'm currently working on implementing a show and hide functionality for a div. I followed a tutorial from a website called w3schools, but the way they implemented it is different from what I'm looking to achieve. In their example, the div is init ...

When a page first loads in Next.js with Firebase, the useEffect hook may return an undefined value

My component is designed to retrieve a subcollection from firestore: import { useEffect, useState } from "react"; import { db } from '../firebase/firebaseInit' import {useAuth} from '../components/AuthContextProvider' import { ...

Top Tip for conditionally rendering a styled component inside or outside a wrapper, depending on the screen width

Can anyone help me with this coding question? I'm currently trying to determine the most efficient way to conditionally place the code inside or outside of the wrapper. However, I am unsure what the best practice for this would be. This process seems ...

A guide to updating MUI Card content when hovering

I'm interested in transforming a Card that currently only displays an image into one that also includes content. Specifically, I want my portfolio to showcase my project's logo initially, and then upon hovering over it, reveal the title, language ...

Half of the sections will not stack on mobile devices

UPDATE I found and fixed a typo in the code, making adjustments to both the JSFiddle and this post to show the correction. The Headline is supposed to take up 100% height but currently isn't. Still seeking feedback on this issue. Everything looks per ...