How does the CSS button hover animation work? - css

I am trying to understand these block of code for button-hovering effect yet still confused.
I can understand when mouse over the button the .btn:hover::after kicks in and display the background(z=-1) button then expand it with transform: scaleX(1.4) scaleY(1.6);
However when mouse pointer move away from the button, the background button also does "shrinking" effect seems like from transform: scaleX(1.4) scaleY(1.6); to normal size. I just couldn't understand which line of code controls this mouse-away animation.
.btn:link,
.btn:visited {
position: relative;
border-radius: 10rem;
display: inline-block;
margin-top: 6rem;
text-transform: uppercase;
text-decoration: none;
padding: 1.5rem 4rem;
transition: all 0.2s;
}
.btn:hover {
transform: translateY(-.3rem);
box-shadow: 0 1rem 2rem rgba(0, 0, 0, .3);
}
.btn:active {
transform: translateY(-.1rem);
box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .2);
}
.btn--white {
background-color: #fff;
color: #777;
}
.btn::after {
content: "";
display: inline-block;
height: 100%;
width: 100%;
border-radius: 10rem;
position: absolute;
top: 0;
left: 0;
z-index: -1;
transition: all .4s;
}
.btn--white::after {
background-color: #fff;
}
.btn:hover::after {
transform: scaleX(1.4) scaleY(1.6);
opacity: 0;
}

The secret lies in transition: all 0.2s in the :link / :visited of the button. transition not only transitions in to the target state, but also out from the target state. Essentially, it's transition that's controlling both sides of the animation that you're seeing.
It's still the transform that's applying the actual offset, but transition is responsible for smoothly fading back and forth on whether the transform is applied or not -- without transition, the animation would simply 'jump' between the two states.
body {
background: black;
}
.btn:link,
.btn:visited {
position: relative;
border-radius: 10rem;
display: inline-block;
margin-top: 6rem;
text-transform: uppercase;
text-decoration: none;
padding: 1.5rem 4rem;
transition: all 0.2s;
}
.btn:hover {
transform: translateY(-.3rem);
box-shadow: 0 1rem 2rem rgba(0, 0, 0, .3);
}
.btn:active {
transform: translateY(-.1rem);
box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .2);
}
.btn--white {
background-color: #fff;
color: #777;
}
.btn::after {
content: "";
display: inline-block;
height: 100%;
width: 100%;
border-radius: 10rem;
position: absolute;
top: 0;
left: 0;
z-index: -1;
transition: all .4s;
}
.btn--white::after {
background-color: #fff;
}
.btn:hover::after {
transform: scaleX(1.4) scaleY(1.6);
opacity: 0;
}
Button

Related

CSS3 problem with animation when unchecking a checkbox

I'm trying to recreate my form's checkboxes by CSS3.
I animated the mark (checkbox) correctly, but when I uncheck the checkbox I can't start the animation in reverse mode. I reproduced my example.
/*
==================
INPUT CHECKBOX
==================
*/
.checkbox-label>input {
display: none;
outline: none;
}
/*
==============
LABEL CHECKBOX
==============
*/
.checkbox-label {
display: block;
position: relative;
font-size: 0.95em;
margin-bottom: 10px;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
outline: none;
}
.checkbox-label:hover>.checkbox-button {
box-shadow: 0px 0px 0px 5px hsla(255, 100%, 60%, 0.1);
background-color: hsla(255, 100%, 60%, 0.1);
}
.checkbox-label:hover>.checkbox-button {
border: 2px solid #808080;
}
/*
======================
MARK CHECKBOX - AFTER
======================
*/
.checkbox-label>input[type="checkbox"]~.checkbox-button::after {
content: "";
position: absolute;
top: 8px;
left: 3px;
border-right: 2px solid transparent;
border-bottom: 2px solid transparent;
transform: rotate(45deg);
transform-origin: left bottom;
}
/*
================================
MARK CHECKBOX - AFTER - CHECKED
================================
*/
.checkbox-label>input[type="checkbox"]:checked~.checkbox-button::after {
animation: checkbox-check 0.3s cubic-bezier(0.5, 0, 0.23, 1);
animation-fill-mode: forwards;
animation-direction: normal;
}
.checkbox-label:not(:active)>input[type="checkbox"]:not(:checked)~.checkbox-button::after {
animation-direction: reverse;
}
/*
========
CHECKBOX
========
*/
.checkbox-button {
vertical-align: sub;
}
.checkbox-button {
position: relative;
top: 0px;
left: 0px;
color: #808080;
height: 20px;
width: 20px;
background-color: transparent;
border: 2px solid #ccc;
border-radius: 5px;
display: inline-block;
transition: background-color 0.4s ease;
}
.checkbox-label>input:checked~.checkbox-button {
background-color: transparent;
border: 2px solid #6633ff;
background-color: #6633ff;
}
.checkbox-label>input~.checkbox-button::before {
content: "";
position: absolute;
left: -8px;
top: -8px;
width: 35px;
height: 35px;
background-color: #6633ff;
border-radius: 30%;
opacity: 0.6;
transform: scale(0);
}
.checkbox-label>input:checked~.checkbox-button::before {
animation: ripple 0.9s ease-out;
}
/*
==========
ANIMATION
==========
*/
#keyframes ripple {
0% {
transform: scale(0);
}
50% {
transform: scale(1);
}
100% {
opacity: 0;
transform: scale(1);
}
}
#keyframes checkbox-check {
0% {
width: 0px;
height: 0px;
border-color: white;
transform: translate3d(0, 0, 0) rotate(45deg);
}
33% {
width: 5px;
height: 0px;
transform: translate3d(0, 0px, 0) rotate(45deg);
}
100% {
width: 5px;
height: 11px;
border-color: white;
transform: translate3d(0, -11px, 0) rotate(45deg);
}
}
<form action="" method="post" class="form">
<h1>Custom Checkboxe</h1>
<label class="checkbox-label" data-label="One">
<input type="checkbox" checked="checked" />
<span class="checkbox-button"></span>
One
</label>
</form>
Let me know what I'm doing wrong and how to improve to make my animation work properly.

How to create button with rounded sides?

I need to create button like this
You can see a rounded borders on center of sides. I'm tried to do it with after and before classes, but it was tricky. Which solution is the cleanest? Also I'm done on dev resizeble button and it'll be better if this can be done as one figure, without absolute positioning or smth like that
body {
background-color: #000;
display: flex;
justify-content: center;
align-items: center;
}
button {
text-transform: uppercase;
background-color: #F9EFCA;
border: none;
padding: 20px 100px;
cursor: pointer;
letter-spacing: 1px;
border-bottom: 10px solid #ae9e5c !important;
box-shadow: inset 0 -1px 1px 0 rgba(0, 0, 0, .12), 0 10px 20px -5px rgba(0, 0, 0, .25);
font-size: 50px;
transition: .2s all;
position: relative;
border-radius: 10px;
}
button:hover,
button:active {
transition: .2s all;
border-bottom: none !important;
}
button:before,
button:after {
content: '';
position: absolute;
top: 9%;
bottom: 0;
height: 91%;
background: #F9EFCA;
width: 10px;
border-radius: 100%;
}
button:before {
left: -4px;
}
button:after {
right: -4px;
}
button:active:before,
button:active:after,
button:hover:before,
button:hover:after {
top: 9%;
bottom: 0;
height: 82%;
}
<button>Call me</button>
Codepen example
create a new button class and try this in your CSS:
.button_costum
{
margin: 10px auto;
font-size: 2.0rem;
padding: 1.25rem 2.5rem;
display: block;
background-color: // choose what you want
border: 1px solid transparent;
color: // choose what you want
font-weight: 300;
-webkit-border-radius: 3px;
border-radius: 20px; // in your case it shout be 25 or 30
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
try using the property on button
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
This would help you target the button corners without distorting the shape of the button itself.

CSS :nth-of-type() Selector for nuxt-link

I'm trying to get a css menu working but want to use vuejs/nuxt-link instead of a traditional a href as this is a single page application Im trying to learn how to build
I have the following
How do I convert this to work with nuxt-link instead of a href
Thanks
HTML I currently have
<nav class="radial">
<input type="checkbox" id="menu" checked>
About
Resume
Blog
Github
a
<label for="menu" class='fa-bars'>Menu</label>
</nav>
I'd like to use (for example) in my html, assuming this is possible.
<nuxt-link :to="'/about'"><fa icon="bars" /></nuxt-link>
The css I currently have is as follows
nav.radial {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
position: relative;
top: -2.5rem;
width: 3rem;
height: 3rem;
margin: 0 100px;
}
nav.radial input {
display: none;
}
nav.radial > label,
nav.radial > a {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #21618C;
color: white;
text-align: center;
font-size: 0;
line-height: 3rem;
}
nav.radial label:before,
nav.radial a:before {
font-size: 1.2rem;
color: white;
}
nav.radial a {
color: transparent;
text-decoration: none;
box-sizing: border-box;
}
nav.radial label {
border-radius: 0 0 1.5rem 1.5rem;
cursor: pointer;
box-sizing: border-box;
border-bottom: 0.25rem solid #2f2f2f;
box-shadow: 0 0.1875rem rgba(0, 0, 0, 0.25);
transition: border-bottom 0.25s, box-shadow 0.5s;
}
nav.radial input:checked ~ label {
border-bottom-width: 1px;
box-shadow: none;
}
nav.radial a[href] {
transition: top 0.1s, left 0.25s, opacity 1s, box-shadow 0.25s;
border-radius: 1.5rem;
opacity: 0;
box-shadow: 0 0 0 rgba(0, 0, 0, 0);
border-bottom: 1px solid #888;
box-sizing: border-box;
}
nav.radial a[href]:hover {
background-color: #E6EDF2;
border-bottom-color: #2c7768;
}
nav.radial input:checked ~ a[href] {
transition: top 1s, left 0.6s, box-shadow 1s, background-color 0.25s, border-bottom-color 0.25s, border-bottom-width 0.25s;
opacity: 1;
}
nav.radial a[href]:hover {
border-bottom-width: 0.25rem;
}
nav.radial input:checked ~ a[href]:nth-of-type(1),
nav.radial input:checked ~ a[href]:nth-of-type(5) {
box-shadow: 0 -0.1875rem 0.375rem rgba(0, 0, 0, 0.25);
}
nav.radial input:checked ~ a[href]:nth-of-type(1) {
left: -4.72707721rem;
top: 0.83351125rem;
}
nav.radial input:checked ~ a[href]:nth-of-type(2) {
left: -3.08538053rem;
top: 3.67701333rem;
}
nav.radial input:checked ~ a[href]:nth-of-type(3) {
left: 0rem;
top: 4.8rem;
}
nav.radial input:checked ~ a[href]:nth-of-type(4) {
left: 3.08538053rem;
top: 3.67701333rem;
}
nav.radial input:checked ~ a[href]:nth-of-type(5) {
left: 4.72707721rem;
top: 0.83351125rem;
}
many thanks for any assistance in advance

CSS3 animation error

.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 1s;
}
#-webkit-keyframes {
0% {background-color:#4CAF50;}
25% {background-color: red;}
50% {background-color: yellow;}
75% {background-color: blue;}
100% {background-color: orange;}
}
.button2:hover {
height: 250px;
min-width: 200px;
font-size: 75px;
font-family: american captain;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
transform: rotate(360deg);
}
<button class="button button2">Shadow on Hover</button>
I have started learning css3 animations. All the animations which i wanted to do seem to run fine except for the color change which i have put in 'keyframes'. The website from which I was learning animations showed the exact same way but it doesn't seem to work on my project. Any help would be highly appreciated. Thanks :-)
You have to give the animation a name..and then apply that animation as a property...
#-webkit-keyframes color-change {
0% {
background-color: #4CAF50;
}
25% {
background-color: red;
}
50% {
background-color: yellow;
}
75% {
background-color: blue;
}
100% {
background-color: orange;
}
}
.button {
animation: color-change 12s ease infinite;
}
.button {
background-color: #4CAF50;
/* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
animation: color-change 12s ease infinite;
-webkit-transition-duration: 0.4s;
/* Safari */
transition-duration: 1s;
}
#-webkit-keyframes color-change {
0% {
background-color: #4CAF50;
}
25% {
background-color: red;
}
50% {
background-color: yellow;
}
75% {
background-color: blue;
}
100% {
background-color: orange;
}
}
.button2:hover {
height: 250px;
min-width: 200px;
font-size: 75px;
font-family: american captain;
box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
transform: rotate(360deg);
}
<button class="button button2">Shadow on Hover</button>

Media queries with CSS in WordPress

I am using a theme with wordpress 3.8. I have included some touch effects in my code that I would like to turn off for tablet and phone devices. I've created a new css without hover effects and put it in my main style sheet under:
#media all and (max-width: 699px) and (min-width: 520px)
However it does not seem to be working. I have seen posts Media Queries CSS along with several other posts on the topic but I cannot get it to work correctly. Any suggestions?
Original CSS:
.view {
width: 300px;
height: 200px;
margin: 10px;
float: left;
border: 10px solid #fff;
overflow: hidden;
position: relative;
text-align: center;
box-shadow: 1px 1px 2px #e6e6e6;
cursor: default;
background: #fff url(../images/bgimg.jpg) no-repeat center center
}
.view .mask, .view .content {
width: 300px;
height: 200px;
position: absolute;
overflow: hidden;
top: 0;
left: 0
}
.view img {
display: block;
height: 100%;
max-width: 100%;
vertical-align: middle;
height: max;
padding: 10px 20px 20px;
position: relative
}
.view h2 {
text-transform: uppercase;
color: #fff;
text-align: center;
position: relative;
font-size: 17px;
padding: 10px;
background: rgba(0, 0, 0, 0.8);
margin: 20px 0 0 0
}
.view p {
font-family: Georgia, serif;
font-style: italic;
font-size: 12px;
position: relative;
color: #fff;
padding: 10px 20px 20px;
text-align: center
}
.view a.info {
display: inline-block;
text-decoration: none;
padding: 7px 14px;
background: #000;
color: #fff;
text-transform: uppercase;
box-shadow: 0 0 1px #000
}
.view a.info:hover {
box-shadow: 0 0 5px #000
}
.view-first img {
transition: all 0.2s linear;
}
.view-first .mask {
opacity: 0;
background-color: rgba(219,127,8, 0.7);
transition: all 0.4s ease-in-out;
}
.view-first h2 {
transform: translateY(-100px);
opacity: 0;
transition: all 0.2s ease-in-out;
}
.view-first p {
transform: translateY(100px);
opacity: 0;
transition: all 0.2s linear;
}
.view-first a.info{
opacity: 0;
transition: all 0.2s ease-in-out;
}
.view-first:hover img {
transform: scale(1.1);
}
.view-first:hover .mask {
opacity: 1;
}
.view-first:hover h2,
.view-first:hover p,
.view-first:hover a.info {
opacity: 1;
transform: translateY(0px);
}
.view-first:hover p {
transition-delay: 0.1s;
}
.view-first:hover a.info {
transition-delay: 0.2s;
}
media css
#media only screen and (min-device-width: 340px) {
.view {
width: 300px;
height: 200px;
margin: 10px;
float: left;
border: 10px solid #fff;
overflow: hidden;
position: relative;
text-align: center;
box-shadow: 1px 1px 2px #e6e6e6;
cursor: default;
background: #fff url(../images/bgimg.jpg) no-repeat center center
}
.view .mask, .view .content {
width: 300px;
height: 200px;
position: absolute;
overflow: hidden;
top: 0;
left: 0
}
.view img {
display: block;
height: 100%;
max-width: 100%;
vertical-align: middle;
height: max;
padding: 10px 20px 20px;
position: relative
}
.view h2 {
text-transform: uppercase;
color: #fff;
text-align: center;
position: relative;
font-size: 17px;
padding: 10px;
background: rgba(0, 0, 0, 0.8);
margin: 20px 0 0 0
}
.view p {
font-family: Georgia, serif;
font-style: italic;
font-size: 12px;
position: relative;
color: #fff;
padding: 10px 20px 20px;
text-align: center
}
.view a.info {
display: inline-block;
text-decoration: none;
padding: 7px 14px;
background: #000;
color: #fff;
text-transform: uppercase;
box-shadow: 0 0 1px #000
}
.view a.info {
box-shadow: 0 0 5px #000
}
.view-first img {
transition: all 0.2s linear;
}
.view-first .mask {
opacity: 0;
background-color: rgba(219,127,8, 0.7);
transition: all 0.4s ease-in-out;
}
.view-first h2 {
transform: translateY(-100px);
opacity: 0;
transition: all 0.2s ease-in-out;
}
.view-first p {
transform: translateY(100px);
opacity: 0;
transition: all 0.2s linear;
}
.view-first a.info{
opacity: 0;
transition: all 0.2s ease-in-out;
}
.view-first img {
transform: scale(1.1);
}
.view-first .mask {
opacity: 1;
}
.view-first h2,
.view-first p,
.view-first:hover a.info {
opacity: 1;
transform: translateY(0px);
}
.view-first p {
transition-delay: 0.1s;
}
.view-first a.info {
transition-delay: 0.2s;
this works.
#media only screen and (max-device-width: 340px)
Using #media and removing the hover selectors from your css code allows the hover effects to show up on tablets and phones. This is a simple solution and negates the need to use any javascript to make your css work on touchscreen devices.
Possible duplicate: #Media min-width & max-width
instead of all and use only screen and and instead of max-width use min-device-width This should solve your issue
EDIT:
For example you can't do this:
Original:
.view a.info:hover {
box-shadow: 0 0 5px #000
}
New:
.view a.info {
box-shadow: 0 0 5px #000
}
It will still have the HOVER because it's in the original file and it will use it.. What you can do is change the original to affect all screens other then the ones you want changed..
For example:
Screen with min size of 500px will have HOVER effect and here you add:
.view a.info:hover {
box-shadow: 0 0 5px #000
}
but for second media screen so anything under 500
.view a.info{
box-shadow: 0 0 5px #000
}
This would work... Now in your case you can try have a HOVER but keep it blank inside
#media only screen and (max-width: 768px) {p{color:orange;}}
#media only screen and (min-width: 770px) {p{color:green;}}

Resources