Customize the appearance of semantic-ui-react components with hover effects

When I assign a specific className to components like

<Segment className="Change" color='blue' inverted></Segment>

and then in my CSS I apply the following:

.Change:hover{
  background-color: black; //or any other hover effect
}

No changes occur on hover. I've observed that some components do not respond to my styling changes, seemingly at random. One Semantic component may allow me to adjust the width while another does not. Could this be due to the same issue? How can I successfully override the hover color?

Answer №1

Upon inspecting the source code of the Segment Component (github), I noted that it comes with two default classes: segment and ui. Furthermore, you have utilized the props color=blue and inverted. To enhance this, I suggest implementing the following code snippet.

.ui.segment.blue.inverted.Change:hover {
  background-color: black !important;
}

View the interactive DEMO

Answer №2

Feel free to choose any color provided by semantic-ui, for example:

<Form>
      <Form.Input label="Email" type="email" />
      <Form.Input label="Password" type="password" />
      <Button color="teal" type="submit">
        Sign In
      </Button>
</Form>

Your button will look like this:

https://i.stack.imgur.com/nA3JF.png

If you want to add inverted styling, use the additional props provided by react semantic-ui:

<Form>
      <Form.Input label="Email" type="email" />
      <Form.Input label="Password" type="password" />
      <Button inverted color="teal" type="submit">
        Sign In
      </Button>
</Form>

This will change the appearance of your component to:

https://i.stack.imgur.com/Ni8YL.png

Hovering over the button will revert it back to its original style if inverted.

Enhancing components with styled components and react semantic ui

I suggest utilizing styled-components to easily customize semantic-ui styles:

import { Tab, Form, Button, Grid, Icon } from "semantic-ui-react";
import styled from "styled-components";

const Mybutton = styled(Button)`
 &:hover {
    color: #fff !important;
 }
`;

Replace the original semantic-ui component with your newly styled one:

<Mybutton inverted color="teal" type="submit">
   Sign In
</Mybutton>

Answer №3

Since the full code was not provided, it is difficult to determine which specific style you are attempting to override. Consider incorporating the !important rule into this particular style.

.Change:hover {
  background-color: black !important;
}

Instead of relying on !important, which may not always be the best solution, try using a more targeted CSS selector such as Segment.Change:hover.

UPDATE: Remove color='blue' from the template and test whether it works with or without the !important rule.

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

Sophisticated Arrangement of Div Elements

Here's a scenario where Two divs are dynamically styled from the Database. I am attempting to align two divs in the layout shown here: https://i.stack.imgur.com/nYI7v.png Can this be achieved using Bootstrap's CSS class col-? In responsive mo ...

Struggling with CSS, seeking improvements to align with my previous coding style

After spending a considerable amount of time working on my game, I made the decision to change my navigation bars to buttons. However, I'm facing issues while trying to finalize the style that I had previously. Here is the old code fiddle: https://js ...

What is the best way to place an icon within a React Material Ui text field?

Is there a way to place the eye icon inside a text field used for passwords in Material UI? I've been trying but haven't found a way to do it yet. Here's the code snippet I'm using: <TextField variant="outlined" ...

Looking to adjust the appearance of the MUI button depending on its current state

I have searched extensively for a solution to my specific React issue but have come up empty-handed. I am relatively new to React, so any help would be greatly appreciated. The problem I'm facing is with a MUI button that changes its state depending ...

Error: Unable to find command "yarn" with sudo privileges; likewise, "create-react-app" command

When I was attempting to set up react on my system, I discovered there are two methods for installation: either through npm or yarn. As an Ubuntu 18.04 user, I already had node and npm installed. name@admin-desktop:~$ node -v v16.14.0 name@admin-desktop:~$ ...

Place an image at the center with a height set to 100% within a div that has a fixed height and

Apologies for asking about this topic again, but I have been unable to find a solution where the image fills 100% of the height. If you'd like to see the issue in action, here's a link to the jsfiddle: http://jsfiddle.net/BBQvd/3/ I'm just ...

Guide on how to add a file path reference into an HTML table

I am encountering an issue with internal links within HTML tables in Docusaurus. I need to showcase intricate tables that are not supported in standard markdown format, and include links to other pages inside table cells. For instance, an MDX file include ...

Handling Click and Mouse Events with React [react-sortable-hoc, material-ui, react-virtualized]

I have come across an interesting example that I would like to share with you. Check out this live working example on Stackblitz When the delete button on the red bin icon is pressed, the onClick event handler does not get triggered (sorting happens inst ...

How can you handle all HTML tags with Regex in a single line of code?

I've developed a PHP script that converts all inline CSS in HTML tags to classes. Visit the following link for more information: https://gist.github.com/iBars/aa52c6119e53908c91ac553aeba229e0 However, it currently only processes tags that are the onl ...

Modifying CSS to ensure compatibility with various browsers

I am curious if it is possible to modify some CSS when viewed in a different browser. For instance, I have this CSS for a flexbox div: .wdFlex { display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -webkit- ...

Should the ListItem expand and collapse when clicked?

My react/material-ui component has the following structure: export const TodoItem: React.FC<Props> = ( {todo, itemKey}) => { const [dialogState, setDialogState] = React.useState<boolean>(false); const handleClose = () => { setDial ...

Update the dropdown field selection to the color #333 with the help of javascript

I am facing an issue with a dropdown field that has placeholder text and options to select. Initially, both the placeholder text and the options were in color #333. However, I managed to change the color of the placeholder text to light grey using the foll ...

Ways to retrieve the state from the Redux store

While working on setting up the Redux store in my app.js file, I found myself populating it with data from the database. However, now I am faced with the task of obtaining the state of the store in a plain JavaScript file, not a React class. If I was work ...

The selected text on the webpage is not showing up highlighted

Encountering an unusual issue that is challenging to comprehend and difficult to find a solution for using Google search. I have created a website with multiple web pages. Each page follows the same format: header with links at the top, content area in th ...

"Utilize the parent component's functionality by extending/inheriting it

export default function PageTemplate() { return ( <div className="layout"> <LeftMenu /> <div className="content"> <TopMenu /> <div id="other-contents"> ...

Place the h1 text inside of a div tag for organization

Here is an example of HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <tit ...

Label text facing positioning difficulties

Hey there! I have a goal in mind: https://i.stack.imgur.com/bnso9.png This is what I currently have: http://codepen.io/KieranRigby/pen/QyWZxV. Make sure to view it in "Full page" mode. label { color: #6d6e70; bottom: 0; } .img-row img { width: 10 ...

What is the best way to navigate users to a different page when they click on a button?

I recently designed a button in Dreamweaver software. Could you please guide me on how to set up the button so that when clicked, it redirects the user to a different page using Dreamweaver? Below is the HTML code for the button: <input type="submit" ...

React input not maintaining focus when value prop is passed through the Router "component" attribute

Today I'm experiencing a mental block. Despite trying numerous solutions to different versions of the issue, I can't seem to find the right one. This seems to be one of those off-weeks where my brain is just not cooperating. The problem I'm ...

The border length of the unordered list is equal to half of the length

I would like the blue borders of these "ul" elements to be centered beneath the black "li" elements, with a width that is 50% of the child width. However, I'm unsure about how to achieve this. I attempted using ":before", but it only seems to work for ...