Style button when :active different from :hover

前端 未结 3 332
深忆病人
深忆病人 2021-01-28 07:37

I want to make a button that displays a background color when hovering and a button color without a background color when the button is down. Here is my current code:

         


        
相关标签:
3条回答
  • 2021-01-28 07:48

    You have to set a new background color on :hover state

    .windowButton:hover {
        background-color:#1a82b8;
    }
    .windowButton:active {
       fill:#1a82b8;
       background-color:#000000;/*You can put the color you want*/
    }
    

    Pseudo states inherit values. For consistency purposes, it is best to only declare the styles which you are changing in your pseudo state rules.

    Note: :hover MUST come after :link and :visited (if they are present) in the CSS definition, in order to be effective!

    0 讨论(0)
  • 2021-01-28 07:53

    How about this?

    I would guess, its cause on the first property you are using background-color and the second fill.

    button:hover {
        background-color: red;
    }
    button:active {
        background-color: blue;
    }
    

    jsFiddle working example (1)

    0 讨论(0)
  • 2021-01-28 08:08

    `button:hover{background-color: transparent;color: yellow;}

    button:active {background: white;color: black;}`

    0 讨论(0)
提交回复
热议问题