I want to animate a css-arrow (pointing to the left) on hover to move slightly right on hover and stay there. Once the mouse hovers out the arrow it should move backwards with the animation as well.
#-webkit-keyframes arrow-left {
0% {
-webkit-transform: translateX(0);
transform:translateX(0);
}
20% {
-webkit-transform:translateX(0);
transform:translateX(0);
}
100% {
-webkit-transform:translateX(-12px);
transform:translateX(-12px);
}
}
#keyframes arrow-left {
0% {
-webkit-transform:translateX(0);
transform:translateX(0);
}
20% {
-webkit-transform:translateX(0);
transform:translateX(0);
}
100% {
-webkit-transform:translateX(-12px);
transform:translateX(-12px);
}
}
.arrow-icon.left:hover {
-webkit-animation:arrow-left 0.35s ease-in;
animation:arrow-left 0.35s ease-in;
-webkit-transform-origin:50% 0%;
-ms-transform-origin:50% 0%;
transform-origin:50% 0%
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
Any idea on how to make the animation out work as well, so it animates back and doesn't jump back?
https://jsfiddle.net/gsvjwxxj/
Instead of using keyframes to perform the translate, use transition plus cubic-bezier.
$(document).ready(function(){
$('.menu-icon').click(function(){
$(this).toggleClass('open');
});
/*setTimeout(function () {
$('.mouse-icon').fadeOut(250, function() { $(this).remove(); });
}, 5000);*/
});
* {
margin: 0;
padding: 0;
}
body {
margin: 100px;
}
/* ---------------------------------------------- /*
* Animated arrow icon
/* ---------------------------------------------- */
.arrow-icon {
position: relative;
width:26px;
height:4px;
background:#000;
cursor: pointer;
-webkit-transition: width .15s ease-in-out, -webkit-transform 0.3s cubic-bezier( 0.42, 0.08, 0.18, -0.24);
-moz-transition: width .15s ease-in-out, -moz-transform 0.3s cubic-bezier( 0.42, 0.08, 0.18, -0.24);
-o-transition: width .15s ease-in-out, -o-transform 0.3s cubic-bezier( 0.42, 0.08, 0.18, -0.24);
transition: width .15s ease-in-out, transform 0.3s cubic-bezier( 0.42, 0.08, 0.18, -0.24);
}
.arrow-icon.left:hover, .arrow-icon.right:hover {
width:36px;
}
.arrow-icon.down:hover, .arrow-icon.up:hover {
height:36px;
}
.arrow-icon.down:hover:after{
top: 15px;
}
.arrow-icon:before {
position:absolute;
content:"";
}
.arrow-icon.left:before, .arrow-icon.right:before {
width: 52px;
height: 26px;
}
.arrow-icon.down:before, .arrow-icon.up:before {
width: 26px;
height: 52px;
}
.arrow-icon:before {
position:absolute;
content:"";
width: 52px;
height: 26px;
}
.arrow-icon.left:before {
top: -12px;
left: -12px;
}
.arrow-icon.right:before {
top: -12px;
left: -12px;
}
.arrow-icon.down:before {
top: -12px;
left: -12px;
}
.arrow-icon.up:before {
top: -12px;
left: -12px;
}
.arrow-icon:after {
position:absolute;
content:"";
transform:rotate(45deg);
top:-8px;
width:16px;
height:16px;
background:transparent;
border-color: #000;
}
.arrow-icon.left:after{
border-left:4px solid;
border-bottom:4px solid;
}
.arrow-icon.right:after{
right:0;
border-right:4px solid;
border-top:4px solid;
}
.arrow-icon.down, .arrow-icon.up {
width: 4px;
height: 26px;
left: 10px;
}
.arrow-icon.down:after{
top: 6px;
left:-8px;
border-right:4px solid;
border-bottom:4px solid;
}
.arrow-icon.up:after {
top:0px;
left:-8px;
border-right:4px solid;
border-top:4px solid;
transform:rotate(-45deg);
}
.arrow-icon.left{
-webkit-transform-origin:50% 0%;
-ms-transform-origin:50% 0%;
transform-origin:50% 0%;
}
.arrow-icon.left:hover {
transform:translateX(-12px);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="arrow-icon left"></div>
you don't have to use animation for this. you can just use transform:translateX(-12px)
see here > fiddle
or snippet below :
let me know if it helps
* {
margin: 0;
padding: 0;
}
body {
margin: 100px;
}
/* ---------------------------------------------- /*
* Animated arrow icon
/* ---------------------------------------------- */
.arrow-icon {
position: relative;
width:26px;
height:4px;
background:#000;
cursor: pointer;
-webkit-transition: .15s ease-in-out;
-moz-transition: .15s ease-in-out;
-o-transition: .15s ease-in-out;
transition: .15s ease-in-out;
}
.arrow-icon.left:hover, .arrow-icon.right:hover {
width:36px;
}
.arrow-icon:before {
position:absolute;
content:"";
}
.arrow-icon.left:before, .arrow-icon.right:before {
width: 52px;
height: 26px;
}
.arrow-icon:before {
position:absolute;
content:"";
width: 52px;
height: 26px;
}
.arrow-icon.left:before {
top: -12px;
left: -12px;
}
.arrow-icon:after {
position:absolute;
content:"";
transform:rotate(45deg);
top:-8px;
width:16px;
height:16px;
background:transparent;
border-color: #000;
-webkit-transition: .1s ease-in-out;
-moz-transition: .1s ease-in-out;
-o-transition: .1s ease-in-out;
transition: .1s ease-in-out;
}
.arrow-icon.left:after{
border-left:4px solid;
border-bottom:4px solid;
}
.arrow-icon.left:hover {
-webkit-transform:translateX(-12px);
transform:translateX(-12px);
-ms-transform-origin:50% 0%;
transform-origin:50% 0%;
}
<div class="arrow-icon left"></div>
Related
This question already has answers here:
How can I write a ':hover' condition for 'a:before' and 'a:after'?
(7 answers)
Closed 4 years ago.
I used the following code snippet to get the effect on the Submit buttons in the form.
Codepen Link
HTML:
a.bttn-dark:hover {
color: #FFF;
}
a.bttn-dark:focus {
color: #FFF;
}
.bttn:before {
-webkit-transition: 0.5s all ease;
transition: 0.5s all ease;
position: absolute;
top: 0;
left: 50%;
right: 50%;
bottom: 0;
opacity: 0;
content: '';
background-color: #FF0072;
z-index: -2;
}
.bttn:hover:before {
-webkit-transition: 0.5s all ease;
transition: 0.5s all ease;
left: 0;
right: 0;
opacity: 1;
}
<div class="flex">
Continue
</div>
<div class="flex dark">
Continue
</div>
I am confused about the usage of following,
what would be different if a:hover is only used instead of a.bttm-dark:hover ?
bttn:before and bttn:hover:before
why is the pseudo element bttn:hover appearing in the HTML document after bttn element? Shouldn't it come before?
Follow below css code.
CSS:
a.bttn {
color: #FF0072;
text-decoration: none;
}
a.bttn-dark {
color: #644cad;
text-decoration: none;
}
a.bttn:hover {
color: #FFF;
}
a.bttn-dark:hover {
color: #FFF;
}
a.bttn-dark:focus {
color: #FFF;
}
.bttn {
font-size:18px;
letter-spacing:2px;
text-transform:uppercase;
display:inline-block;
text-align:center;
width:270px;
font-weight:bold;
padding:14px 0px;
border:3px solid #FF0072;
border-radius:2px;
position:relative;
box-shadow: 0 2px 10px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.1);
}
.bttn:before {
-webkit-transition:0.5s all ease;
transition:0.5s all ease;
position:absolute;
top:0;
left:50%;
right:50%;
bottom:0;
opacity:0;
content:'';
background-color:#FF0072;
z-index:-2;
}
.bttn:hover {
-webkit-transition:0.5s all ease;
transition:0.5s all ease;
left:0;
right:0;
opacity:1;
}
.bttn:focus {
transition:0.5s all ease;
left:0;
right:0;
opacity:1;
}
.bttn:hover:before {
-webkit-transition: 0.5s all ease;
transition: 0.5s all ease;
left: 0;
right: 0;
opacity: 1;
}
.bttn-dark {
font-size:18px;
letter-spacing:2px;
text-transform:uppercase;
display:inline-block;
text-align:center;
width:270px;
font-weight:bold;
padding:14px 0px;
border:3px solid #644cad;
border-radius:2px;
position:relative;
box-shadow: 0 2px 10px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.1);
}
.bttn-dark:before {
-webkit-transition:0.5s all ease;
transition:0.5s all ease;
position:absolute;
top:0;
left:50%;
right:50%;
bottom:0;
opacity:0;
content:'';
background-color:#644cad;
z-index:-2;
}
.bttn-dark:hover {
-webkit-transition:0.5s all ease;
transition:0.5s all ease;
left:0;
right:0;
opacity:1;
}
.bttn-dark:focus {
transition:0.5s all ease;
left:0;
right:0;
opacity:1;
}
.bttn-dark:hover:before {
-webkit-transition: 0.5s all ease;
transition: 0.5s all ease;
left: 0;
right: 0;
opacity: 1;
}
I want to make a hover effect, when hover the image like this:
On the Internet found many similar examples but they all either with jquery or js. I would like to know whether it is possible to do purely with css...
UPDATE: here's a code found, but it is too big :(
.view-content {
height: 330px;
}
h2.view-title {
font-size: 3rem;
font-weight: bold;
color: #7d7a7a;
text-align: center;
text-shadow: 0 0px 0px;
}
.view {
width: 300px;
height: 200px;
margin: 10px;
float: left;
border: 5px solid #fff;
overflow: hidden;
position: relative;
text-align: center;
box-shadow: 0px 0px 5px #aaa;
cursor: default;
}
.view .view-mask, .view {
width: 300px;
height: 200px;
position: absolute;
overflow: hidden;
top: 0;
left: 0;
}
.view img {
display: block;
position: relative;
}
.view a.view-info {
display: inline-block;
text-decoration: none;
padding:0;
text-align: center;
color: white;
font-size: 1.9rem;
font-weight: 600;
vertical-align: middle;
}
.view-effect .view-mask {
opacity: 0;
overflow:visible;
border:100px solid rgba(0,0,0,0.7);
box-sizing:border-box;
transition: all 0.3s ease-in-out;
}
.view-effect a.view-info {
position:relative;
top:-20px;
opacity: 0;
transition: opacity 0.3s 0s ease-in-out;
}
.view-effect:hover .view-mask {
opacity: 1;
border:100px solid rgba(0,0,0,0.7);
}
.view-effect:hover a.view-info {
opacity:1;
transition-delay: 0.3s;
}
<div class="view view-effect">
<img src="http://storage7.static.itmages.ru/i/16/0708/h_1467979220_8325708_d41d8cd98f.png" height="200" width="300" alt=""> <p></p>
<div class="view-mask">
Show project
</div>
</div>
Checkout below code as what you want or just click on below link :-
https://jsfiddle.net/ananddeepsingh/99bop25r/
HTML
<div class="box"> <img src="http://placehold.it/400x300">
<div class="overbox">
<div class="title overtext"> CSS Script </div>
<div class="tagline overtext"> Animated Text Overlay On Hover </div>
</div>
</div>
CSS
.box {
cursor: pointer;
height: 300px;
position: relative;
overflow: hidden;
width: 400px;
}
.box img {
position: absolute;
left: 0;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
}
.box .overbox {
background-color: #304562;
position: absolute;
top: 0;
left: 0;
color: #fff;
z-index: 100;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
opacity: 0;
width: 360px;
height: 240px;
padding: 130px 20px;
}
.box:hover .overbox {
opacity: 1;
}
.box .overtext {
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
transform: translateY(40px);
-webkit-transform: translateY(40px);
}
.box .title {
font-size: 2.5em;
text-transform: uppercase;
opacity: 0;
transition-delay: 0.1s;
transition-duration: 0.2s;
}
.box:hover .title,
.box:focus .title {
opacity: 1;
transform: translateY(0px);
-webkit-transform: translateY(0px);
}
.box .tagline {
font-size: 0.8em;
opacity: 0;
transition-delay: 0.2s;
transition-duration: 0.2s;
}
.box:hover .tagline,
.box:focus .tagline {
opacity: 1;
transform: translateX(0px);
-webkit-transform: translateX(0px);
}
Yes you can do that using pure CSS. for that purpose you may use :after pseudo class as,
.img-wrapper {
position:relative;
display:inline-block;
overflow:hidden;
cursor:pointer
}
.img-wrapper .hover-div{
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
opacity:0;
display:inline-block;
text-align:center;
background:rgba(0,0,0,0.3);
-webkit-transition: 0.5s ease-in-out;
-moz-transition: 0.5s ease-in-out;
-o-transition: 0.5s ease-in-out;
transition: 0.5s ease-in-out;
-webkit-transform: translateY(100%);
-moz-transform: translateY(100%);
-o-transform: translateY(100%);
-ms-transform: translateY(100%);
transform: translateY(100%);
}
.img-wrapper:hover .hover-div{
top:0;
opacity:1;
-webkit-transform: translateY(0);
-moz-transform: translateY(0);
-o-transform: translateY(0);
-ms-transform: translateY(0);
transform: translateY(0);
}
.img-wrapper:hover img {
-webkit-filter:grayscale(1);
-moz-filter:grayscale(1);
filter:grayscale(1);
}
.mybutton{
background:#FFFFFF;
color:#111111;
padding:10px 20px;
border-radius:5px;
display:inline-block;
margin-top:100px;
-webkit-transition: 0.3s ease-in-out;
transition: 0.3s ease-in-out;
}
.mybutton:hover{
background:#111111;
color:#FFFFFF;
}
<div class="img-wrapper">
<img src="https://unsplash.it/200" >
<div class="hover-div">
<a class="mybutton">My Button</a>
</div>
</div>
Just use ':hover' after the element you want to show the effect on. For example, if you wanted to use it on the header you would create a new css tag called
header:hover{} and then you could put an opactiy of maybe 0.5 to make the object fade on hover. Hope this helps!
Yes it is possible only through HTML and CSS. Below there is an example code:
HTML:
<div class="imagebox">
<div class="transparent"><i class="fa fa-search" aria-hidden="true"></i>
<p>Zoom</p></div>
<img src="images/yourimage.jpg">
</div>
CSS:
.imagebox{
position: relative;
}
.imagebox:hover .transparent{
display: block;
}
.transparent{
background: rgba(0,0,0,0.5);
position: absolute;
height: 100%;
width: 100%;
display: none;
cursor: pointer;
}
.transparent i{
position: absolute;
left: 50%;
top: 30%;
color: #fff;
font-size: 20px;
}
.transparent p{
position: absolute;
left: 45%;
top: 50%;
color: #fff;
font-size: 20px;
}
.button {
text-align: left;
background-color: #012839;
text-decoration: none;
text-transform: uppercase;
font-family: 'Exo 2', sans-serif;
font-weight: 200;
font-size: 30px;
display: inline-block;
position: relative;
margin-top: 50px;
margin-left: 20px;
text-align: center;
width: 50px;
color: #00c7ec;
border: 1px solid #00c7ec;
border-radius: 5px;
line-height: 3em;
padding-left: 5em;
padding-right: 5em;
box-shadow: 0 0 0 0 transparent;
-webkit-transition: all 0.2s ease-in;
-moz-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
}
.button:hover {
color: white;
box-shadow: 0 0 30px 0 rgba(0, 199, 236, 0.5);
background-color: #00c7ec;
-webkit-transition: all 0.2s ease-out;
-moz-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
}
.button:hover:before {
-webkit-animation: shine 0.5s 0s linear;
-moz-animation: shine 0.5s 0s linear;
animation: shine 0.5s 0s linear;
}
.button:active {
box-shadow: 0 0 0 0 transparent;
-webkit-transition: box-shadow 0.2s ease-in;
-moz-transition: box-shadow 0.2s ease-in;
transition: box-shadow 0.2s ease-in;
}
.button:before {
content: '';
display: block;
width: 0px;
height: 86%;
position: absolute;
top: 7%;
left: 0%;
opacity: 0;
background: white;
box-shadow: 0 0 15px 3px white;
-webkit-transform: skewX(-20deg);
-moz-transform: skewX(-20deg);
-ms-transform: skewX(-20deg);
-o-transform: skewX(-20deg);
transform: skewX(-20deg);
}
#-webkit-keyframes shine {
from {
opacity: 0;
left: 0%;
}
50% {
opacity: 1;
}
to {
opacity: 0;
left: 100%;
}
}
#-moz-keyframes shine {
from {
opacity: 0;
left: 0%;
}
50% {
opacity: 1;
}
to {
opacity: 0;
left: 100%;
}
}
#keyframes shine {
from {
opacity: 0;
left: 0%;
}
50% {
opacity: 1;
}
to {
opacity: 0;
left: 100%;
}
}
Gallery
I wanted to use this button in my personal project but the problem I am having is that the text in the button i.e. "Gallery" is not getting center aligned even after I put the "text-align:"center" in the button class.
Because of you define width 50px; now do this
add width: auto; or remove width: 50px;
as like this
.button {
text-align: left;
background-color: #012839;
text-decoration: none;
text-transform: uppercase;
font-family: 'Exo 2', sans-serif;
font-weight: 200;
font-size: 30px;
display: inline-block;
position: relative;
margin-top: 50px;
margin-left: 20px;
text-align: center;
color: #00c7ec;
border: 1px solid #00c7ec;
border-radius: 5px;
line-height: 3em;
padding-left: 5em;
padding-right: 5em;
box-shadow: 0 0 0 0 transparent;
-webkit-transition: all 0.2s ease-in;
-moz-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
}
.button:hover {
color: white;
box-shadow: 0 0 30px 0 rgba(0, 199, 236, 0.5);
background-color: #00c7ec;
-webkit-transition: all 0.2s ease-out;
-moz-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
}
.button:hover:before {
-webkit-animation: shine 0.5s 0s linear;
-moz-animation: shine 0.5s 0s linear;
animation: shine 0.5s 0s linear;
}
.button:active {
box-shadow: 0 0 0 0 transparent;
-webkit-transition: box-shadow 0.2s ease-in;
-moz-transition: box-shadow 0.2s ease-in;
transition: box-shadow 0.2s ease-in;
}
.button:before {
content: '';
display: block;
width: 0px;
height: 86%;
position: absolute;
top: 7%;
left: 0%;
opacity: 0;
background: white;
box-shadow: 0 0 15px 3px white;
-webkit-transform: skewX(-20deg);
-moz-transform: skewX(-20deg);
-ms-transform: skewX(-20deg);
-o-transform: skewX(-20deg);
transform: skewX(-20deg);
}
#-webkit-keyframes shine {
from {
opacity: 0;
left: 0%;
}
50% {
opacity: 1;
}
to {
opacity: 0;
left: 100%;
}
}
#-moz-keyframes shine {
from {
opacity: 0;
left: 0%;
}
50% {
opacity: 1;
}
to {
opacity: 0;
left: 100%;
}
}
#keyframes shine {
from {
opacity: 0;
left: 0%;
}
50% {
opacity: 1;
}
to {
opacity: 0;
left: 100%;
}
}
Gallery
Add .button { width: auto; } to get your result
change
padding-left : 5em to 2.5em
I had removed padding and added min-width:220px:
.button {
text-align: left;
background-color: #012839;
text-decoration: none;
text-transform: uppercase;
font-family: 'Exo 2', sans-serif;
font-weight: 200;
font-size: 30px;
display: inline-block;
position: relative;
margin-top: 50px;
margin-left: 20px;
text-align: center;
color: #00c7ec;
min-width: 220px; /*Here you can give any value other then 220px*/
border: 1px solid #00c7ec;
border-radius: 5px;
line-height: 3em;
box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
-webkit-transition: all 0.2s ease-in;
-moz-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
}
.button:hover {
color: white;
box-shadow: 0 0 30px 0 rgba(0, 199, 236, 0.5);
background-color: #00c7ec;
-webkit-transition: all 0.2s ease-out;
-moz-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
}
.button:hover:before {
-webkit-animation: shine 0.5s 0s linear;
-moz-animation: shine 0.5s 0s linear;
animation: shine 0.5s 0s linear;
}
.button:active {
box-shadow: 0 0 0 0 transparent;
-webkit-transition: box-shadow 0.2s ease-in;
-moz-transition: box-shadow 0.2s ease-in;
transition: box-shadow 0.2s ease-in;
}
.button:before {
content: '';
display: block;
width: 0px;
height: 86%;
position: absolute;
top: 7%;
left: 0%;
opacity: 0;
background: white;
box-shadow: 0 0 15px 3px white;
-webkit-transform: skewX(-20deg);
-moz-transform: skewX(-20deg);
-ms-transform: skewX(-20deg);
-o-transform: skewX(-20deg);
transform: skewX(-20deg);
}
#-webkit-keyframes shine {
from {
opacity: 0;
left: 0%;
}
50% {
opacity: 1;
}
to {
opacity: 0;
left: 100%;
}
}
#-moz-keyframes shine {
from {
opacity: 0;
left: 0%;
}
50% {
opacity: 1;
}
to {
opacity: 0;
left: 100%;
}
}
#keyframes shine {
from {
opacity: 0;
left: 0%;
}
50% {
opacity: 1;
}
to {
opacity: 0;
left: 100%;
}
}
Gallery
On this LIVE DEMO you can see how animation works in each div moves its image and gives opacity:1 to text.
When hover-off, naturally all styles get back to their initial state directly, but I want them to do it smoothly(ease), instead of setting all initial styles at the same time with no progress.
Here it is related animation code:
#highlights div[class*="high-"]:hover > p {
-webkit-animation:downOp 0.3s ease-in 0s forwards;
-ms-animation:downOp 0.3s ease-in 0s forwards;
animation:downOp 0.3s ease-in 0s forwards;
}
#highlights div[class*="high-"]:hover > .image {
-webkit-animation:imgTrans 5s ease-out 0s forwards;
-ms-animation:imgTrans 5s ease-out 0s forwards;
animation:imgTrans 5s ease-out 0s forwards;
}
#-webkit-keyframes downOp {
0% {
opacity:0.7;
}
100% {
opacity:1;
}
}
#-ms-keyframes downOp {
0% {
opacity:0.7;
}
100% {
opacity:1;
}
}
#keyframes downOp {
0% {
opacity:0.7;
}
100% {
opacity:1;
}
}
#-webkit-keyframes imgTrans {
0% {
margin-right: 0;
}
100% {
margin-right: -50px;
}
}
#-ms-keyframes imgTrans {
0% {
margin-right: 0;
}
100% {
margin-right: -50px;
}
}
#keyframes imgTrans {
0% {
margin-right: 0;
}
100% {
margin-right: -50px;
}
}
Use css transform instead of css animation! It will automatically handle hover-out effect!
See your fiddle here
See my modified effect jsfiddle
html
<article id="highlights">
<div class="high-rinoplastia">
<div class="image"></div>
<p><strong>Rinoplastia</strong>
<br> <span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod</span>
</p>
</div>
</article>
css
#highlights {
min-height: 525px;
width: 1170px;
margin:0 auto;
}
#highlights div[class*="high-"] {
border: 1px solid rgba(0, 0, 0, 0.28);
display: inline-block;
float: left;
height: 150px;
margin: 10px;
position: relative;
width: calc(33% - 20px);
overflow: hidden;
}
#highlights .image {
height:100%;
transition:all 4s ease;
}
#highlights p {
background-color: white;
bottom: 0;
height: 60px;
margin-bottom: 0px;
position: absolute;
opacity:0.7;
transition:all 0.6s ease;
}
#highlights span {
display: block;
font-size: 12px;
margin: 2px;
}
#highlights:hover p {
opacity:1;
}
#highlights:hover .image {
transform:all 5s ease;
margin-right: -50px;
}
#highlights .high-rinoplastia .image {
background: url(http://mypet.guru/wp-content/uploads/2014/06/fluffy-cats-009.jpg) no-repeat right center;
}
#highlights .high-venas .image {
background: url(http://mypet.guru/wp-content/uploads/2014/06/fluffy-cats-009.jpg) no-repeat right center;
}
#highlights .high-cirugiaCalvicie .image {
background: url(http://mypet.guru/wp-content/uploads/2014/06/fluffy-cats-009.jpg) no-repeat right center;
}
#highlights .high-tratamientoCalvicie .image {
background: url(http://mypet.guru/wp-content/uploads/2014/06/fluffy-cats-009.jpg) no-repeat right center;
}
Everything remains same just add transition to p and image element.
#highlights .image {
height:100%;
-webkit-transition: all 0.5s ease; // increase 0.5s to whatever you wish in order to add more smoothness
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#highlights p {
background-color: white;
bottom: 0;
height: 60px;
margin-bottom: 0px;
position: absolute;
opacity:0.7;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
I am not sure if this is expected for CSS :after pseudo class.
What do I have ?
I am trying to create a tooltip using CSS. Following is the HTML and CSS I am using. Fiddle HERE
HTML
<div class="tooltip tooltip-left">
:(
</div>
CSS
.tooltip {
display:inline-block;
position:absolute;
background: #002663;
height:100px;
width:300px;
color:#fff;
padding:20px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
/*TOP*/
.tooltip-top:after {
content:"";
display: block;
position:absolute;
bottom:-20px;
left:50%;
border-top:20px solid #002663;
border-left:20px solid transparent;
border-right:20px solid transparent;
margin-left:-20px;
};
/*LEFT*/
.tooltip-left:after {
content:"";
display: block;
position:absolute;
right: -20px;
top: 50%;
border-left: 20px solid #002663;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
margin-top: -20px;
};
What's so weird?
The tooltip does not contain the arrow in the current fiddle. However if I comment the class .tooltip-top:after the arrow appears.
Why is this behavior? Cant I declare multiple definitions for :after pseudo element using different classes applied to same element?
You have a trailing semi colon after the .tooltip-top:after class. Remove it. It's causing the next class not to be read.
.tooltip-top:after {
content:"";
display: block;
position:absolute;
bottom:-20px;
left:50%;
border-top:20px solid #002663;
border-left:20px solid transparent;
border-right:20px solid transparent;
margin-left:-20px;
}; /* <-- This ; is what's causing the problem */
UPDATED FIDDLE
CSS:
[data-tips] {
position: relative;
text-decoration: none;
}
[data-tips]:after,
[data-tips]:before {
position: absolute;
z-index: 100;
opacity: 0;
}
[data-tips]:after {
content: attr(data-tips);
height: 25px;
line-height: 25px;
padding: 0 10px;
font-size: 12px;
text-align: center;
color: #fff;
background: #222;
border-radius: 5px;
text-shadow: 0 0 5px #000;
-moz-box-shadow: 0 0 5px rgba(0,0,0,0.3);
-webkit-box-shadow: 0 0 5px rgba(0,0,0,0.3);
box-shadow: 0 0 5px rgba(0,0,0,0.3);
white-space: nowrap;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
[data-tips]:before {
content: "";
width: 0;
height: 0;
border-width: 6px;
border-style: solid;
}
[data-tips]:hover:after,
[data-tips]:hover:before {
opacity: 1;
}
/* Top tips */
[data-tips].top-tip:after,
[data-tips].top-tip:before {
-webkit-transition: bottom 0.25s ease-in-out, opacity 0.25s ease-in-out;
-moz-transition: bottom 0.25s ease-in-out, opacity 0.25s ease-in-out;
transition: bottom 0.25s ease-in-out, opacity 0.25s ease-in-out;
bottom: 90%;
left: -9999px;
margin-bottom: 12px;
}
[data-tips].top-tip:before {
border-color: #222 transparent transparent transparent;
margin-bottom: 0;
}
[data-tips].top-tip:hover:after,
[data-tips].top-tip:hover:before {
bottom: 100%;
left: 0;
}
[data-tips].top-tip:hover:before {
left: 15px;
}
/* Bottom tip */
[data-tips].bottom-tip:after,
[data-tips].bottom-tip:before {
-webkit-transition: top 0.25s ease-in-out, opacity 0.25s ease-in-out;
-moz-transition: top 0.25s ease-in-out, opacity 0.25s ease-in-out;
transition: top 0.25s ease-in-out, opacity 0.25s ease-in-out;
top: 90%;
left: -9999px;
margin-top: 12px;
}
[data-tips].bottom-tip:before {
border-color: transparent transparent #222 transparent;
margin-top: 0;
}
[data-tips].bottom-tip:hover:after,
[data-tips].bottom-tip:hover:before {
top: 100%;
left: 0;
}
[data-tips].bottom-tip:hover:before {
left: 15px;
}
/* Left tip */
[data-tips].left-tip:after,
[data-tips].left-tip:before {
-webkit-transition: left 0.25s ease-in-out, opacity 0.25s ease-in-out;
-moz-transition: left 0.25s ease-in-out, opacity 0.25s ease-in-out;
transition: left 0.25s ease-in-out, opacity 0.25s ease-in-out;
top: -9999px;
left: 96%;
margin-left: 12px;
}
[data-tips].left-tip:before {
border-color: transparent #222 transparent transparent;
margin-left: 0;
}
[data-tips].left-tip:hover:after,
[data-tips].left-tip:hover:before {
left: 100%;
top: 0;
}
[data-tips].left-tip:hover:before {
top: 7px;
}
/* Right tip */
[data-tips].right-tip:after,
[data-tips].right-tip:before {
-webkit-transition: right 0.25s ease-in-out, opacity 0.25s ease-in-out;
-moz-transition: right 0.25s ease-in-out, opacity 0.25s ease-in-out;
transition: right 0.25s ease-in-out, opacity 0.25s ease-in-out;
top: -9999px;
right: 96%;
margin-right: 12px;
}
[data-tips].right-tip:before {
border-color: transparent transparent transparent #222;
margin-right: 0;
}
[data-tips].right-tip:hover:after,
[data-tips].right-tip:hover:before {
right: 100%;
top: 0;
}
[data-tips].right-tip:hover:before {
top: 7px;
}
HTML :
bavotasan.com
add the data-tips="" parameter to any HTML element plus a class to set the direction and a tooltip will appear.
Try following link :
http://cbavota.bitbucket.org/css3-tips/