Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change styling on hover semantic-ui-react components

if I set up a className for certain components like

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

and in my css I use

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

nothing is overriden on the hover.

I have also noticed there are many other components that refuse changes of mine, seemingly randomly. One semantic component will let me change a width the next will not. Is the cause from the same issue? How do I override the color on a hover?

like image 213
DORRITO Avatar asked Feb 17 '18 14:02

DORRITO


2 Answers

After reviewing the source code of Segment Component (github), I found it has two default classes: segment and ui. In addition, you used two props color=blue and inverted. So I would recommend using the following code.

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

Working DEMO

like image 56
fyasir Avatar answered Oct 16 '22 09:10

fyasir


Choose any color semantic-ui provide 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 appears like:

enter image description here

You can add inverted props inside Button component that react semantic-ui provide

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

your component appears like:

enter image description here

On hover returns to basic style opposite of inverted

styled components usage with react semantic ui

I recommended you to use styled-components in order to override semantic-ui component style

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

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

Next use your new styled component instead of semantic-ui

<Mybutton inverted color="teal" type="submit">
   Sign In
</Mybutton>
like image 2
xargr Avatar answered Oct 16 '22 09:10

xargr