简体   繁体   中英

How to transition an item to move to the left on hover

I would like my element (which i have named as a class benefits-button) to slide in from the left upon hover. I have created the following two sets of css rules but I am having no luck:

.benefit-buttons {
     transition-property: color, left;
     transition-duration: 200ms;
     transition-delay: .1s;
     transition-timing-function: ease-in-out;
}
.benefit-buttons:hover {
    opacity: 1;
    color: #FF0000;
    left: 50%;
}

 .benefit-buttons { -webkit-transition: all 1s ease-in-out; -moz-transition: all 1s ease-in-out; -o-transition: all 1s ease-in-out; -ms-transition: all 1s ease-in-out; width:100px; height:100px; background:red; } .benefit-buttons:hover { opacity: 1; color: #FF0000; transform:translate(50%); } 
 <div class="benefit-buttons"></div> 

An element cannot have a left property unless it's absolutely-positioned ( read more ). Try a left margin as an alternative:

.benefit-buttons {
    width: 25%;
    transition-property: all;
    transition-duration: 200ms;
    transition-delay: .1s;
    transition-timing-function: ease-in-out;
}

.benefit-buttons:hover {
    opacity: 1;
    color: #FF0000;
    margin-left: 10%;
}

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM