Rotating a background image with CSS3

前端 未结 2 1043
无人及你
无人及你 2021-01-02 03:13

I have a background image that has an arrow that points to the right. When a user clicks on the button, the selected state changes the arrow to point down (using a different

2条回答
  •  长情又很酷
    2021-01-02 03:56

    you could use the ::after (or ::before) pseudo-element, to generate the animation

    div /*some irrelevant css */
    {
        background:-webkit-linear-gradient(top,orange,orangered);
        background:-moz-linear-gradient(top,orange,orangered);
        float:left;padding:10px 20px;color:white;text-shadow:0 1px black;
        font-size:20px;font-family:sans-serif;border:1px orangered solid;
        border-radius:5px;cursor:pointer;
    }
    
    /* element to animate */
    div::after               /* you will use for example "a::after" */
    {
        content:' ►';        /* instead of content you could use a bgimage here */
        float:right;
        margin:0 0 0 10px;
        -moz-transition:0.5s all;
        -webkit-transition:0.5s all;
    }
    
    /* actual animation */
    div:hover::after         /* you will use for example "a.selected::after" */
    {
        -moz-transform:rotate(90deg);
        -webkit-transform:rotate(90deg);
    }
    

    HTML:

    Test button

    in your case you will use element.selected class instead of

    jsfiddle demo: http://jsfiddle.net/p8kkf/

    hope this helps

提交回复
热议问题