CSS after mouse is moved from hover - html

In CSS, the hover event is triggering as it should. However, when it is an animation, when the mouse is moved back off the object (in this case a button), it returns to its normal state without an animation back. This results in it looking really jumping and going against the theme I'm shooting for. So, I need an event that is triggered after the hover event, like what I thought would work: .button-default:hover:after {}, but didn't work the way I expected. My CSS below:
.button-default {
width: 40vw;
height: 5vh;
color: white;
background: transparent;
border: solid 2px;
border-radius: 5px;
border-color: white;
}
.button-default:hover {
animation-name: animate-button;
animation-duration: 2s;
animation-fill-mode: forwards;
}
.button-default:hover:after {
animation-name: normalize-button;
animation-duration: 2s;
animation-fill-mode: forwards;
}
#keyframes normalize-button {
from {
color: blue;
background: white;
border-color: blue;
}
to {
width: 40vw;
height: 5vh;
color: white;
background: transparent;
border: solid 2px;
border-radius: 5px;
border-color: white;
}
}
#keyframes animate-button {
from {
.button-default;
}
to {
color: blue;
background: white;
border-color: blue;
}
}
body {
font-family: 'Oswald', sans-serif;
/*background: url('../images/novam.png') no-repeat center;*/
background: black;
background-size: cover;
}

As your animation only need two stages, you can just use css transition instead of animation to get that effect. And FYI, after is pseudo element. It is not event.
.button-default {
width: 40vw;
height: 5vh;
color: white;
background: transparent;
border: solid 2px;
border-radius: 5px;
border-color: white;
-webkit-transition: all 2s ease;
transition: all 2s ease;
-moz-transition: all 2s ease;
}
.button-default:hover {
color: blue;
background: white;
border-color: blue;
}
Fiddle here

Related

how do I position my element on css based on the screen border

I want to position my element (the button) based on the size of the screen, with what I have done, it works pretty well until i make the screen size a bit smaller, then the box starts going out of screen on the right side, how do i fix this?
.button1 {
background-color: #ffffff;
border: 2px solid #e5ff00;
color: rgb(0, 0, 0);
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 8px;
position: relative;
cursor: pointer;
}
.buttonbox{
position: relative;
animation-name: moving;
animation-duration: 2s;
animation-iteration-count: infinite;
}
.button1:hover{
background-color: #e5ff00;
transition: 0.5s;
}
#keyframes moving {
0%{
padding-left: 0%;
}
100%{
padding-left: 90%;
}
}
<div class= "buttonbox">
<form action="https://www.faster.rent/">
<button class="button1" type="submit">click Here!</button>
</form>
</div>
Basically what you are trying to do is get the width of the viewport (screen width) and pad to the left of your button, minus the width of the button.
This can be done by using calc in your keyframes:
#keyframes moving {
0%{
padding-left: 0%;
}
100%{
padding-left: calc(100vw - 162px);
}
}
where 100vw corresponds to 100% of the viewport width.
.button1 {
background-color: #ffffff;
border: 2px solid #e5ff00;
color: rgb(0, 0, 0);
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 8px;
position: relative;
cursor: pointer;
width: 142px;
}
.buttonbox{
position: relative;
animation-name: moving;
animation-duration: 2s;
animation-iteration-count: infinite;
}
.button1:hover{
background-color: #e5ff00;
transition: 0.5s;
}
#keyframes moving {
0%{
padding-left: 0%;
}
100%{
padding-left: calc(100vw - 162px);
}
}
<!DOCTYPE html>
<html>
<header>
<link rel="stylesheet" type="text/css" href="./style.css"/>
</header>
<div class= "buttonbox">
<form action="https://www.faster.rent/">
<button class="button1" type="submit">click Here!</button>
</form>
</div>
</html>
first make the buttonbox width:100% and the position:relative, make the button position:absolute,then you can animate the button inside buttonbox
.button1 {
position: absolute;
background-color: #ffffff;
border: 2px solid #e5ff00;
color: rgb(0, 0, 0);
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 8px;
cursor: pointer;
animation-name: moving;
animation-duration: 2s;
animation-iteration-count: infinite;
}
.buttonbox{
width: 100%;
position: relative;
}
.button1:hover{
background-color: #e5ff00;
transition: 0.5s;
}
#keyframes moving {
0%{
left:0% }
100%{
left: 85%;
}
}
<div class= "buttonbox">
<form action="https://www.faster.rent/">
<button class="button1" type="submit">click Here!</button>
</form>
</div>
Using media Query is another ways to handle this scenario. We can use the media query to control animation to avoid having button hide behind the scroll. So in this scenario, i have created two animation moving and movingSmall.
.button1 {
background-color: #ffffff;
border: 2px solid #e5ff00;
color: rgb(0, 0, 0);
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 8px;
position: relative;
cursor: pointer;
}
.buttonbox{
width: 100%;
position: relative;
animation-name: moving;
animation-duration: 3s;
animation-iteration-count: infinite;
}
#media all and (max-width: 600px) {
.buttonbox{
animation-name: movingSmall;
}
}
.button1:hover{
background-color: #e5ff00;
transition: 0.5s;
}
#keyframes movingSmall {
0%{
left:0
}
100%{
left: 65%;
}
}
#keyframes moving {
0%{
left:0
}
100%{
left: 80%;
}
}
<div class= "buttonbox">
<form action="https://www.faster.rent/">
<button class="button1" type="submit">click Here!</button>
</form>
</div>

transition css top and bottom

How can I make such animation ?
(https://i.stack.imgur.com/NTWjH.png)
please check link below
https://preview.themeforest.net/item/shopify-outstock-clean-minimal-drag-drop/full_screen_preview/21041667?_ga=2.52492833.847676305.1666954417-2031082058.1666954417
.wrap-img {
transition: all 200ms ease 0s;
-webkit-transition: all 200ms ease 0s;
-moz-transition: all 200ms ease 0s;
overflow: hidden;
margin: 0px auto;
position: relative;
background: #fff;
padding: 15px;
}
One option would be this:
.box {
/* Required for the position: absolute property of the overlay. */
position: relative;
}
/* Scroll up and down effect */
.scrolling {
background-size: cover !important;
width: 285px;
min-height: 500px;
border: 15px solid #fff; /* Border is white */
cursor: pointer;
transition: background-position 1.5s ease-out 0.5s
}
.scroll {
background: url("https://velatheme.com/demo/outstock/images/cosmetic2.jpg");
background-position: top center;
}
.scroll_top:hover {
background-position: bottom center !important;
transition: background-position 2s linear 0s;
}
/* Background separating the image and the button */
.overlay {
position: absolute;
display: flex;
justify-content: center;
align-items:center;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: rgba(0,0,0,0.4);
}
.box:hover .overlay {
opacity: 1;
}
/* Button */
button {
display: none;
}
.box:hover button {
display: inline-block;
height: 48px;
width: 158px;
border: 4px solid #fff;
text-align: center;
line-height: 30px;
font-size: 14px;
font-weight: 600;
text-transform: uppercase;
color: #333;
}
.box button:hover {
display: inline-block;
color: #fff;
background: #333;
cursor: pointer
}
<div class="box scrolling scroll scroll_top">
<div class="overlay">
<button>VIEW DEMO</button>
</div>
</div>
To do the opposite effect, you would first have to change the classes to scroll_bottom and it would just change:
In .scroll :
background-position: bottom center;
And in .scroll_top:hover (In this case it would be .scroll_bottom:hover):
background-position: top center !important;

CSS suddenly transition out

Click me for more information
when the mouse icon is moved away from the element, element suddenly returns to original state
(I showed it in the video)
.productinfo {
display: flex;
flex-direction: column;
align-items: center;
margin-left: 1%;
margin-top: 3%;
color: #ff0062;
flex: 0 0 25%;
border: 3px solid #FF00FF;
transition: 1ms;
}
.productinfo:nth-child(-n+3) {
margin-top: 1%;
}
.productinfo:hover {
animation: changeColor 3s, changefontsize 5s forwards;
}
#keyframes changeColor{
33%{border-top: 3px solid #4281A4;}
66%{border-right: 3px solid #4281A4;}
66%{border-left: 3px solid #4281A4;}
100%{border-bottom: 3px solid #4281A4;}
}
#keyframes changefontsize{
0%{font-size: 5;}
25%{font-size: 10;}
50%{font-size: 15;}
100%{font-size: 25px;}
}
This is my current code
Does this approach based on CSS transitions do what you want (only showing added/changed code)?
.productinfo {
transition: border 3s linear, font-size 5s linear;
}
.productinfo:hover {
border: 3px solid #4281A4;
font-size: 25px;
}

How to show full text on hover but after some delay using CSS?

I want to show full text on cursor hover but only after 1s delay. I tried adding transition property but it seems it doesn't apply to absolute elements. Here's the codepen demo.
Here's the code:
.main {
display: flex;
justify-content: center;
}
.main .parent:hover .cell {
position: absolute !important;
z-index: 1 !important;
padding-right: 10px;
background: gray;
transition-delay: 1s;
}
.main .parent {
display: block;
width: 200px;
border-right: 1px solid rgb(237, 237, 236);
white-space: nowrap;
min-height: 32px;
cursor: default;
height: 32px;
padding: 5px 8px 6px;
font-size: 14px;
overflow: hidden;
}
.main .parent .cell {
line-height: 1.5;
white-space: nowrap;
word-break: normal;
pointer-events: none;
}
<main class="main">
<div class="parent">
<span class="cell">
In publishing and graphic design, Lorem ipsum is a placeholder text
commonly used to demonstrate the visual form of a document or a typeface
without relying on meaningful content.</span
>
</div>
</main>
Notice that background color is transiting properly but the full text is shown instantly as soon as I hover.
Looking for a solution to add some delay in showing full text without using any JavaScript.
Finally made it work by using css animation. Working codepan demo
#keyframes hover-delay {
0% {
background: gray;
position:absolute;
}
100% {
background: gray;
position: absolute ;}
}
.parent {
&:hover {
.cell {
z-index: 1 !important;
padding-right: 10px;
animation-name : hover-delay;
animation-delay: 1s;
animation-duration: 2s;
// animation-iteration-count: infinite; // play animation infinite times
// alternate way: retain the style values that is set by the last keyframe
animation-fill-mode: forwards;
}
}
display: block;
width: 200px;
border-right: 1px solid rgb(237, 237, 236);
white-space: nowrap;
min-height: 32px;
cursor: default;
height: 32px;
padding: 5px 8px 6px;
font-size: 14px;
overflow: hidden;
.cell {
line-height: 1.5;
white-space: nowrap;
word-break: normal;
pointer-events: none;
}
}
Works for me, even with position:absolute;
But I went ahead and included a version that uses animation (transition too)
https://jsfiddle.net/56sxzcu7/
/* Using transition */
h1 {
transition:1s;
transition-delay:1s;
opacity:1;
position:absolute;
}
h1:hover {
opacity:0.5;
}
/* Using animate */
h2:hover {
animation: example 2s linear 2s infinite alternate;
}
#keyframes example {
0% {opacity:1;}
100% {opacity:0.5;}
}

How to flash a div only

Can I flash a div using only CSS? I would like this div to flash two colors.
.chat-window .msg-container-base .notification-message-unread{
float: right;
font-size: 10px;
color: #666;
background: white;
padding-left: 10px;
}
Here you go:
.notification-message-unread {
float: right;
font-size: 10px;
color: #666;
background: white;
padding-left: 10px;
display: block;
position: relative;
width: 200px;
height: 200px;
background-color: red;
animation: blinker 1s linear infinite;
}
#keyframes blinker {
50% {
background-color: blue;
}
}
<div class="notification-message-unread"></div>
For this you can use CSS keyframe animations.
.box {
height: 500px;
width: 500px;
animation: animationFrames 5s infinite;
}
#keyframes animationFrames{
0% {
background-color: blue;
}
15% {
background-color: red;
}
30% {
background-color: orange;
}
45% {
background-color: purple;
}
60% {
background-color: green;
}
75% {
background-color: pink;
}
100% {
background-color: black;
}
}
<div class="box"></div>
In the .box class I'm using the animation property to link to an animation keyframe called animationFrames. I'm also defining how long I want this animation to play for, in the example above it's 5s and set to infinite so it repeats forever. The keyframe portion sets what CSS you want to apply to the animation at what percent in the animation, for example at 15% of 5 seconds it will turn red.
You can learn more about CSS keyframe animations here and here.
As per your specific example this code should work (I added a height property just so you could see it)
.chat-window {
float: right;
font-size: 10px;
color: #666;
background: white;
padding-left: 10px;
animation: animationFrames 2s infinite;
height: 500px;
}
#keyframes animationFrames{
50% {
background-color: orange;
}
}
<div class="chat-window"></div>