The hover selector in Material UI and React is not functioning as expected

My code is experiencing an issue where the hover selector does not appear to be working. Although all other styling aspects function correctly, the hover effect is not visible.

import React from "react";
import Paper from '@material-ui/core/Paper';
import Grid from '@material-ui/core/Grid';
const styles = {
    divStyle: {
        width: "300px",
        height: "200px",
        backgroundColor: "red",
        margin: "30px",
        '&:hover': {
            border: '5px solid #000000',
            bordeBottomColor: 'transparent',
            borderRightColor: 'transparent'
        }
    }
};

const StartPage = ()=> {

    return(
        <React.Fragment>
             <Paper>
                <div style={styles.firstContainer}>
                </div>
                <div style={styles.secondContainer}>
                    <Grid container >
                        <Grid style={styles.Grid} item>
                            <div style={styles.gridDivStyle}>
                                <div style={styles.divStyle}></div>
                                <div style={styles.divStyle}></div>
                            </div>
                           <div style={styles.gridDivStyle}>
                                <div style={styles.divStyle}></div>
                                <div style={styles.divStyle}></div>
                            </div>
                        </Grid>
                    </Grid>
                </div>
                <div style={styles.lastContainer}>
                </div>
             </Paper>
        </React.Fragment>
    );

}

export default StartPage;

Is there a way to troubleshoot and fix this hover selector issue? Would incorporating React state help in achieving the desired hover effect?

Answer №1

If you're looking to implement a hover style, consider using the following package:

import { withStyles } from 'material-ui/styles';

Check out the code snippet below:

import React from "react";
import Paper from "@material-ui/core/Paper";
import Grid from "@material-ui/core/Grid";
import { withStyles } from "@material-ui/styles";
const styles = {
  divStyle: {
    width: "300px",
    height: "200px",
    backgroundColor: "red",
    margin: "30px",
    "&:hover": {
      border: "5px solid #000000",
      bordeBottomColor: "transparent",
      borderRightColor: "transparent"
    }
  }
};

const StartPage = props => {
  return (
    <React.Fragment>
      <Paper>
        <div style={styles.firstContainer} />
        <div style={styles.secondContainer}>
          <Grid container>
            <Grid style={styles.Grid} item>
              <div style={styles.gridDivStyle}>
                <div className={props.classes.divStyle} /> // use the styles through className
                <div className={props.classes.divStyle} />
              </div>
              <div style={styles.gridDivStyle}>
                <div className={props.classes.divStyle} />
                <div className={props.classes.divStyle} />
              </div>
            </Grid>
          </Grid>
        </div>
        <div style={styles.lastContainer} />
      </Paper>
    </React.Fragment>
  );
};

export default withStyles(styles)(StartPage);

View Working Demo

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

What is the best way to design a webpage that adapts to different screen heights instead of widths?

I'm in the process of designing a basic webpage for a game that will be embedded using an iframe. The game and text should always adjust to fit the height of your screen, so when the window is small, only the game is displayed. The game will be e ...

Changing the screen size of a panel using asp.net and c#

When my screen size reaches 480px, I want to remove one menu and replace it with another. The solution I'm considering is creating two panels. In this setup, I would set menu1 to false when the screen size is less than 480px and menu2 to true. Conve ...

What is the method for styling the third list item in a CSS hierarchy?

I'm struggling to understand the hierarchy in CSS for creating this specific layout. I've searched for explanations, but haven't found a clear one that breaks down how each level works. This is my first time working with CSS so it's bee ...

`The submit button fails to function properly within the Capacitor application`

Encountering a bug where clicking the Login button does not trigger any action. It works fine in the browser but encounters issues with capacitorJS. Attempts have been made to resolve this by adding an onClick function directly on the button, removing Form ...

FabricJS Canvas with a React DropDown Feature

While I have successfully created a TextBox on FabricJS Canvas, creating a Dropdown component has proven to be a challenge. The fabric.Textbox method allows for easy creation of text boxes, but no such built-in method exists for dropdowns in FabricJS. If y ...

Having trouble displaying the correct data for the Title in NextJs Head? Any solutions available?

Hi there, I am currently utilizing the <Head/> Tag from an API in my NextJs project. All meta tags are functioning properly except for the title meta tag, which seems to be displaying the first H1 on the page instead. Here is the code snippet: ...

Guide on mocking Bugsnag in jest test scenarios for a React application

Bugsnag.initialize({ apiKey: BUGSNAG_KEY, plugins: [new BugsnagPluginReact()], deploymentStage: process.env.NODE_ENV, applicationVersion: APP_VERSION, }) const ErrorCatcher = Bugsnag.getPlugin('react').createErrorCatcher(React) using &q ...

reason behind text styling: thick 12 pixels height with line spacing of 25 pixels using "Arial" font

Question about CSS Size: Understanding font sizes in CSS {font: 14px/24px Arial, Helvetica, sans-serif} I've noticed some CSS code like this on the website .selector {font: bold 12px/25px "Arial";} I know that 'bold' refers to font w ...

Issue with React Project/NEXTJS: 404 Page Not Found

I'm facing an issue while trying to launch a React project utilizing Nextjs. Upon running "yarn run dev," the project fails to load in the browser and the console displays the following errors: GET http://localhost:3000/_next/static/chunks/webpack.js? ...

Utilizing Bootstrap for Efficient Image Alignment

I'm encountering an issue with my code and I am unsure of how to fix it. The current state of my code is different from the desired outcome https://i.sstatic.net/Ti1kK.jpg As you can see, the image above does not match the appearance of the image I ...

The Chrome browser is failing to detect the hover function of the Surface Pen stylus

Encountering an issue with the hover pseudo-class not functioning properly on Surface pad's Chrome browser. The hover effect is working as expected in other browsers, but not in Chrome. I am using a Surface pen to test the hover functionality. HTML: ...

What is the best way to format a text component so that the initial word in each sentence is bolded?

Creating a text component where the first word of the sentence is bold can be a bit tricky. The current solution may result in a messy output like "Tips: favouritevacation" where there is no space after "Tips:". This approach is not very elegant. One pos ...

The Redux toolkit reducer's return function does not properly bind to objects

Could someone help me understand why my attempt to use the Redux toolkit reducer with return method is not working as expected when operating on an object? const initialState ={ cartItems :cartItems, amount:4, total:0, isLoading:true } con ...

Having trouble setting up React-Native project configuration

As a beginner in React-Native, I am currently working on setting up the project on my Mac. Although I successfully created a new project, I am facing challenges with setting up an existing one using WebStorm IDE. I have been trying to do so for a week now ...

Tips for making sure a header is consistently at the top of every page during printing

I need help with my website - I have a table that is quite tall and spans across multiple pages when printing. Is there a way to make the header row appear on top of each page when printing? ...

Are you getting a 403 Forbidden error from Keycloak when trying to access localhost:3000?

Currently in the process of developing a web application with ReactJS, it is being hosted on http://localhost:3000. To ensure security, all backend and web applications are protected by Keycloak. The Keycloak and backend service account are both running on ...

Abundance of DOM elements - the difference between hidden and display none

When I have numerous DOM elements on my page and assign them all a display: none property, the browser continues to perform quickly (smooth scrolling and snappy page response). But if I hide the elements using visibility: hidden instead, the browser slows ...

What is the best way to transfer the information from a renderDetailPanel within React/NextJS (specifically `row`) to the handleSubmit function?

How can I transfer the data from row to the handleSubmit function? For example: const handleSubmit = async (e) => { e.preventDefault(); // working with row data, but how do I access it here?? setExampleData(row.original.ExampleData); //this doesn ...

Enable highlighting a table border when hovering over it

Is there a way to highlight the boundary of a table row when hovering over it? Something like this: I attempted to use CSS with the following code: .ant-table-tbody>tr.ant-table-row:hover>td, .ant-table-tbody>tr>td.ant-table-cell-row-hover{ ...

What is the best way to store data in Firebase as a JSON object?

I need your help with storing a JSON string in Firebase. I have to update my app weekly with data, so I decided to store the information in a JSON format. After using an online tool to stringify it, I got a long string that looks like this: " ...