I have an animation that I want to achieve and I am not able to be getting it right.
I've searched the internet and found some solutions, however they have a slight change in the animation.
I want a border animation that starts at the bottom left goes to top left then top right then bottom right and finally back to bottom left. Each animation after another and the borders once appeared should stay visible afterwards.
This is the code I've managed to get: https://jsfiddle.net/gwbn427m/
div {
width: 300px;
height: 200px;
display: inline-block;
padding: 30px;
/*bottom: -25;*/
position: relative;
border: 0;
}
.draw {
transition: color 0.25s;
}
.draw::before,
.draw::after {
/* Set border to invisible, so we don't see a 4px border on a 0x0 element before the transition starts*/
border: 2px solid transparent;
width: 0;
height: 0;
box-sizing: inherit;
content: '';
position: absolute;
}
/* This covers the top & right borders (expands right, then down)*/
.draw::before {
left: 0;
bottom: 0;
}
/* And this the bottom & left borders (expands left, then up) */
.draw::after {
right: 0;
top: 0;
}
.draw:hover {
color: red;
}
/* Hover styles */
.draw:hover::before,
.draw:hover::after {
width: 100%;
height: 100%;
}
.draw:hover::before {
border-top-color: res; /*Make borders visible */
border-right-color: red;
transition:
width 0.25s ease-out 0.25s, /* And then height */
height 0.25s ease-out; /* Width expands first */
}
.draw:hover::after {
border-bottom-color: red; /* Make borders visible */
border-left-color: red;
transition:
border-color 0s ease-out 0.5s, /* Wait for ::before to finish before showing border*/
width 0.25s ease-out 0.75s, /* And finally height*/
height 0.25s ease-out 0.5s; /*And then exanding width*/
}
<div class="draw">
<img src="http://via.placeholder.com/200x100">
</div>
However I've tried it with those https://codepen.io/sean_codes/pen/YZWqLo keyframe animation and couldn't get it right either.
I really would appreciate any help!
To achieve that you will need two divs so that you can create four different elements using its pseudo elements :before and :after and then use transition-delay to delay the transition
.main {
width: 200px;
height: 200px;
position: relative;
}
.item {
height: 100%;
}
.main:before,
.main:after,
.item:before,
.item:after {
content: "";
position: absolute;
background: red;
}
.main:before {
width: 2px;
height: 0;
bottom: 0;
left: 0;
}
.main:after {
height: 2px;
width: 0;
top: 0;
left: 0;
}
.item:before {
width: 2px;
height: 0;
top: 0;
right: 0;
}
.item:after {
height: 2px;
width: 0;
right: 0;
bottom: 0;
}
.main:hover:before {
height: 100%;
transition: all .5s linear;
}
.main:hover:after {
width: 100%;
transition: all .5s linear .5s;
}
.main:hover .item:before {
height: 100%;
transition: all .5s linear 1s;
}
.main:hover .item:after {
width: 100%;
transition: all .5s linear 1.5s;
}
<div class="main">
<div class="item">
Some Content
</div>
</div>
Related
I have a hover animation that I have created with CSS. When the user hovers over the link the underline transitions from left to right changing the colour from black to grey. Currently as you would expect when the user moves their mouse off the link the transition reverses to start state.
I wondered if it is possible to prevent this reverse transition and instead fade the underline back to the colour black (the original start state)?
Here is a jsfiddle to work with.
Any suggestions/advise would be most welcome.
a.btn--tertiary {
padding-left: 0;
padding-right: 0;
background-color: transparent;
color: #000;
border: 0;
position: relative;
padding-bottom: 5px;
text-transform: uppercase;
text-decoration: none;
font-size: 40px;
}
.btn--tertiary:before {
content: '';
height: 2px;
right: 0;
width: 100%;
background: #000;
position: absolute;
bottom: 0;
opacity: 1;
transition: width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0s;
z-index: 2;
border-left: 10px solid transparent;
}
.btn--tertiary:after {
content: '';
height: 2px;
left: 0;
right: auto;
width: 0%;
background: grey;
position: absolute;
bottom: 0;
transition: width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0.1s;
z-index: 3;
}
.btn--tertiary:hover:before,
.btn--tertiary:focus:before {
width: 0%;
border-left: 20px solid $white;
}
.btn--tertiary:hover::after,
.btn--tertiary:focus::after {
right: 0;
width: 100%;
}
Yes, it is indeed. The trick is to make the width transition out take 0s with a delay of 1s.
html,
body {
margin: 0;
padding: 0;
}
a.btn--tertiary {
padding-left: 0;
padding-right: 0;
background-color: transparent;
color: #000;
border: 0;
position: relative;
padding-bottom: 5px;
text-transform: uppercase;
text-decoration: none;
font-size: 40px;
}
.btn--tertiary::before {
content: '';
height: 2px;
right: 0;
width: 100%;
background: #000;
position: absolute;
bottom: 0;
transition: width 0s;
z-index: 2;
border-left: 10px solid transparent;
}
.btn--tertiary::after {
content: '';
height: 2px;
left: 0;
right: auto;
width: 0%;
background: grey;
position: absolute;
bottom: 0;
opacity: 0;
transition: opacity .5s, width 0s .5s;
z-index: 3;
}
.btn--tertiary:hover:before,
.btn--tertiary:focus:before {
width: 0%;
border-left: 20px solid $white;
transition: width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0s;
}
.btn--tertiary:hover::after,
.btn--tertiary:focus::after {
right: 0;
width: 100%;
opacity: 1;
transition: opacity 0s, width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0.1s;
}
Button
Fiddle.
You can try like below. Check the comments for the details:
a.btn--tertiary {
color: #000;
position: relative;
padding-bottom: 5px;
display:inline-block;
text-decoration:none;
overflow:hidden;
font-size: 40px;
}
.btn--tertiary:before,
.btn--tertiary:after {
content: '';
height: 2px;
position: absolute;
bottom: 0;
}
.btn--tertiary:before {
right: 0;
width: 100%;
background: #000;
border-left: 20px solid #fff;
transition:
background 2s cubic-bezier(0.100, 0.600, 0.350, 1.000); /* transition the background on mouseout*/
}
.btn--tertiary:after {
left: 0;
width: 0%;
background: red;
}
.btn--tertiary:hover:before,
.btn--tertiary:focus:before {
width: 0%;
background: red;
transition:
width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0s, /* visible transition of width on hover */
background 0s 1s; /* no transition but a background change after 1s */
}
.btn--tertiary:hover::after,
.btn--tertiary:focus::after {
right: 0;
width: 100%;
transition:
width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0.1s; /* visible transition of width on hover */
}
Button
I hope this would help, please see the example below.
div {
text-align: center;
margin-top: 20px;
}
.btn--tertiary {
text-decoration: none;
font-family: sans-serif;
text-transform: uppercase;
display: inline-block;
position: relative;
overflow: hidden;
font-size: 45px;
color: black;
}
.btn--tertiary::before {
position: absolute;
content: '';
width: 100%;
height: 3px;
bottom: 0;
left: 0;
background: gray;
transform: scale(0, 1);
transform-origin: right;
transition: transform 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0s;
}
.btn--tertiary:hover::before {
transform: scale(1, 1);
transform-origin: left;
transition: transform 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) .1s;
}
.btn--tertiary::after {
position: absolute;
content: '';
width: 100%;
height: 3px;
bottom: 0;
right: 0;
background: black;
transform: scale(1, 1);
transform-origin: left;
transition: transform 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) .1s;
}
.btn--tertiary:hover::after {
transform: scale(0, 1);
transform-origin: right;
transition: transform 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0s;
}
<div>
Button
</div>
I want to achive a simple animation on hover in css, but while hovering off, the animation jumps and makes it look silly. Is there a way to avoid that?
My wish would be that it is colapsing the same way it originaly transformed.
Codepen: https://codepen.io/misah/pen/abzRXvL
.item {
width: 20%;
height: 0;
padding-top: 20%;
background-color: blue;
position: relative;
transition: 800ms;
}
.item::after {
position: absolute;
bottom: 0;
height: 30%;
width: 100%;
content: "";
background-color: grey;
transition: transform 800ms ease-in-out;
}
.item:hover::after {
transform: scaleY(2);
transform-origin: bottom;
}
<div class="item">
</div>
This happens because the transform-origin: bottom; is only applied when the item is hovered. When not hovered it falls back to the default - center. Move the rule to the declaration of the ::after.
.item {
width: 20%;
height: 0;
padding-top: 20%;
background-color: blue;
position: relative;
transition: 800ms;
}
.item::after {
position: absolute;
bottom: 0;
height: 30%;
width: 100%;
content: "";
background-color: grey;
transition: transform 800ms ease-in-out;
transform-origin: bottom;
}
.item:hover::after {
transform: scaleY(2);
}
<div class="item"></div>
I'm trying to make somekind of toolbox, I need make toolbox apearing from left on opening, so I make transition from left=-1500px to left=0; and that works fine.
when I try make some kind of minimalization adding transition to height=0;width=0; after I added: transition: width, height 1s linear; transition left stop working.
Here is example: https://jsfiddle.net/wsghc65c/7/
my css:
.modal {
visibility: visible;
position: fixed;
z-index: 1;
left: 10%;
top: 10%;
width: 80%;
height: 80%;
margin: auto;
opacity: 1;
padding: 10px;
padding-top: 25px;
border-radius: 15px;
background-color: #aaa;
border-width: thin;
border-style: solid;
transition: visibility 0.1s linear;
transition: left 1s linear;
transition: width, height 1s linear;
}
.modal-content {
overflow: -moz-scrollbars-vertical;
overflow-x: hidden;
overflow-y: scroll;
max-height: 80vh;
mac-width: 86vh;
}
.modal-left-hide {
visibility: hidden;
left: -1500px;
}
.modal.minimized {
width: 0%;
height: 0%;
left: 10vh;
padding: 0;
margin: 0;
}
https://jsfiddle.net/wsghc65c/16/
Add the height width transition to the minimized class. You might want to set overflow hidden too.
.modal.minimized {
width: 0%;
height: 0%;
left: 10vh;
padding: 0;
margin: 0;
transition: width 1s linear, height 1s linear;
}
I would like to animate two borders on hover specifically border-left and border-top. After doing some research it does not seem you can actually "animate" the borders themselves so you have to create a "line" which on hover should have its width set to 100% to have the same effect.
I know how to do this with underlining menu items, but I would like to do it with this box I'm trying to create.
Specifically on hover (while maintaining the css effects already written up)
1) border-left should extend to the top and right after that-> 2) border-top extending from the left to the right.
Also was wondering how I can choose which borders to extend if I don't want to to just do border-left or border-top.
This is my box thus far (unfortunately nothing with animating borders):
CSS:
#txt{
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);
font-size:2vw;
}
#box{
position:fixed;
top:25%;
left:25%;
height:20vw;
width:20vw;
border-right: 2px solid deepskyblue;
border-bottom: 2px solid deepskyblue;
background-color:black;
color:ghostwhite;
}
#box:hover{
color:deepskyblue;
transition: color 0.25s ease;
}
#box:after{
content:"";
position:absolute;
bottom: 0;
left: 0;
width:100%;
height:100%;
transform: scale(0, 0);
transform-origin:bottom right;
background: ghostwhite;
z-index: -1;
transition: transform 0.25s ease;
}
#box:hover::after{
transform: scale(1, 1);
color:deepskyblue;
}
HTML:
<div id="box">
<span id="txt">TEXT</span>
</div>
You can make the #txt element as large as the parent box and then use pseudo-element on that to make "borders" and animate the dimensions of those pseudo-elements.
If you add a transiton-delay in I think you can get the effect you are after.
#txt {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
}
#box {
font-size: 2vw;
position: fixed;
top: 1em;
left: 40vw;
height: 20vw;
width: 20vw;
background-color: black;
color: ghostwhite;
}
#box:hover {
color: deepskyblue;
transition: color 0.25s ease;
}
#box:after {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
transform: scale(0, 0);
transform-origin: bottom right;
background: ghostwhite;
z-index: -1;
transition: transform 0.25s ease;
}
#box:hover::after {
transform: scale(1, 1);
color: deepskyblue;
}
#txt::before {
content: "";
position: absolute;
z-index: 2;
left: 0;
bottom: 0;
height: 0;
}
#txt::before {
width: 0;
border-left: 2px solid deepskyblue;
transition: height .25s .5s ease;
}
#txt:hover::before {
height: 100%;
}
#txt::after {
content: "";
position: absolute;
width: 0%;
top: 0;
left: 0;
border-top: 2px solid deepskyblue;
transition: width 0.25s .75s ease;
}
#txt:hover::after {
width: 100%;
}
<div id="box">
<span id="txt">TEXT</span>
</div>
I am looking for a solution to create an image hover effect and keeping the image same height as widht at the same time. Here is my code right now:
.kozossegitag {
content: "";
display: block;
width: 100%;
padding-top: 100%;
background: url(http://www.kaptarcoworking.hu/wp-content/uploads/2015/07/koren_miklos.jpg);
background-size: cover;
overflow: hidden
}
.reszletek {
width: 100%;
padding-top: 100;
background-color: rgba(67,85,103,0.7);
opacity: 0;
}
.kozossegitag:hover .reszletek {
background-color: rgba(67,85,103,0.5);
opacity: 1;
-webkit-transition: opacity .25s ease;
-moz-transition: opacity .25s ease;
}
<div class="kozossegitag">
<div class="reszletek">
<span>Koren Miklós</span>
</div>
</div>
My goal is to cover the whole image with this pastel blue color and place the text right on the image. As you see here (the left one is without hover, the right one is with):
Many thanks for every help!
Cheers,
Pepe
Add this to your css:
.kozossegitag:hover{
background-color: lightblue;
background-blend-mode: multiply;
}
Here is the JSFiddle demo
It's not overly neat, as it's a little rushed but you get the idea. I used position absolute and some pseudo elements to create what I think you're trying to achieve.
CSS:
.kozossegitag {
display: block;
width: 100%;
background: url(http://www.kaptarcoworking.hu/wp-content/uploads/2015/07/koren_miklos.jpg);
background-size: cover;
overflow: hidden;
position: relative;
}
/* give the div the ratio height */
.kozossegitag::after {
content: "";
padding-top: 100%;
display: block;
}
.reszletek {
width: 100%;
opacity: 0;
}
.kozossegitag:hover .reszletek {
opacity: 1;
-webkit-transition: opacity .25s ease;
-moz-transition: opacity .25s ease;
z-index: 10;
position: relative;
}
/* overlay the light blue using ::before */
.kozossegitag:hover::before {
content: "";
background-color: rgba(67, 85, 103, 0.7);
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 0;
}
Working example.
By positioning .kozossegitag relatively, you can position .reszletek absolutely right over top of it by setting width and height to 100% and top and left to 0.
You also forgot to set height to 0 on .kozossegitag to keep it square;
.kozossegitag {
height:0;
position:relative;
content: "";
display: block;
width: 100%;
padding-top: 100%;
background: url(http://www.kaptarcoworking.hu/wp-content/uploads/2015/07/koren_miklos.jpg);
background-size: cover;
overflow: hidden
}
.reszletek {
position:absolute;
width: 100%;
height: 100%;
top:0;
left:0;
background-color: rgba(67,85,103,0.7);
opacity: 0;
}
.kozossegitag:hover .reszletek {
background-color: rgba(67,85,103,0.5);
opacity: 1;
-webkit-transition: opacity .25s ease;
-moz-transition: opacity .25s ease;
}
Fiddle: http://jsfiddle.net/trex005/rpafw24q/