How to make a hover effect for pseudo elements?

前端 未结 4 414
一向
一向 2020-11-29 01:01

I have a this setup:

Button

and this for CSS:

#button {
    color: #fff;
    display:          


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 01:29

    If its just for design purposes I think its better to create Pseudo-Elements on either side of the Rectangle Box and to keep the HTML as simple as possible:

    HTML:

     
        
    Rectangle

    CSS:

     .tabStyle {
            border-style:solid;
            border-color: #D8D8D8;
            background : #D8D8D8;
            width:200px;
            height:93px;
            color: #000;
            position: relative;
            top: 10px;
            left: 49px;
            text-align:center;
        }
        .tabStyle:hover {
            background : #000;
            border-color: #000;
        }
        .tabStyle:hover::before {
            border-color: transparent #000 #000 transparent;
            border-style: solid;
            border-width: 0px 0px 100px 50px;
        }
        .tabStyle:hover::after {
            border-color: transparent transparent #000 #000;
            border-style: solid;
            border-width: 0px 50px 100px 0px;
        }
        .tabStyle::after {
            border-color: transparent transparent #D8D8D8 #D8D8D8;
            border-style: solid;
            border-width: 0px 50px 100px 0px;
            position: absolute;
            top: -4px;
            left:101%;
            content:"";
        }
        .tabStyle::before {
            border-color: transparent #D8D8D8 #D8D8D8 transparent;
            border-style: solid;
            border-width: 0px 0px 100px 50px;
            position: absolute;
            top: -4px;
            right: 101%;
            content:"";
        }
    

    I've modified the CSS and the result can be seen below:

    http://jsfiddle.net/a3ehz5vu/

提交回复
热议问题