Creating ::after pseudo element causing problems with backface-visibility - html

I'm trying to create a flip card that has a shadow that fades in and out as it flips. I've read that the most efficient way (in terms of rendering) to animate a shadow is to create an ::after pseudo element with opacity of 0 and fade the shadow in. I'm attaching two snippets, one without the shadows that works fine, and the second that has the shadows and has a weird effect. Essentially, when the pseudo elements are there, the backface-visiblity property seems to glitch (or I'm missing something) but basically the back of the card shows immediately before it's even flipped over. I've slowed down the animation and added a red shadow to the back of the card so that it's easy to see what all is happening.
Thanks in advance.
.card {
perspective: 50rem;
background-color: #fff;
box-shadow: 5px 10px 10px rgba(51, 51, 51, 0.8);
width: 200px;
height: 300px;}
.card--flip {
background: none;
box-shadow: none; }
.card__side {
height: 400px;
width: 100%;
box-shadow: none;
background-color: #777;
transition: all 3s ease;
position: absolute;
top: 0;
left: 0;
backface-visibility: hidden; }
.card__side--front::after {
box-shadow: 5px 10px 10px rgba(51, 51, 51, 0.8);
opacity: 1;
transition: all 3s ease; }
.card__side--back {
transform: rotateY(-180deg); }
.card__side--back::after {
box-shadow: 5px 10px 10px rgba(255, 0, 0, 0.8);
opacity: 0;
transition: all 3s ease; }
.card:hover .card__side--front {
transform: rotateY(180deg); }
.card:hover .card__side--front::after {
opacity: 0; }
.card:hover .card__side--back {
transform: rotateY(0); }
.card:hover .card__side--back::after {
opacity: 1; }
.card__header {
padding: 2rem; }
.card__main {
padding: 2rem; }
WORKING
<div class="card card--flip">
<div class="card__side card__side--front">
<div class="card__header">
<h1>FRONT</h1>
</div>
<div class="card__main">front</div>
</div>
<div class="card__side card__side--back">
<div class="card__header">
<h1>BACK</h1>
</div>
<div class="card__main">back</div>
</div>
</div>
.card {
height: 400px;
width: 200px;
perspective: 50rem;
background-color: #fff;
box-shadow: 5px 10px 10px rgba(51, 51, 51, 0.8); }
.card--flip {
background: none;
box-shadow: none; }
.card__side {
width: 100%;
box-shadow: none;
background-color: #777;
transition: all 3s ease;
position: absolute;
top: 0;
left: 0;
backface-visibility: hidden; }
/* ADDED PSEUDO ELEMENT */
.card__side::after {
content: "";
position: absolute;
top: 0;
left: 0;
z-index: -10;
width: 100%;
height: 100%; }
.card__side--front::after {
box-shadow: 5px 10px 10px rgba(51, 51, 51, 0.8);
opacity: 1;
transition: all 3s ease; }
.card__side--back {
transform: rotateY(-180deg); }
.card__side--back::after {
box-shadow: 5px 10px 10px rgba(255, 0, 0, 0.8);
opacity: 0;
transition: all 3s ease; }
.card:hover .card__side--front {
transform: rotateY(180deg); }
.card:hover .card__side--front::after {
opacity: 0; }
.card:hover .card__side--back {
transform: rotateY(0); }
.card:hover .card__side--back::after {
opacity: 1; }
.card__header {
padding: 2rem; }
.card__main {
padding: 2rem; }
NOT WORKING
(added pseudo ::after class)
<div class="card card--flip">
<div class="card__side card__side--front">
<div class="card__header">
<h1>FRONT</h1>
</div>
<div class="card__main">front</div>
</div>
<div class="card__side card__side--back">
<div class="card__header">
<h1>BACK</h1>
</div>
<div class="card__main">back</div>
</div>
</div>

Add the following to your class:
.card {
...
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}

Related

CSS fontAwesome icon doesn´t center [duplicate]

This question already has answers here:
Flexbox: center horizontally and vertically
(14 answers)
How can I center text (horizontally and vertically) inside a div block?
(27 answers)
Closed 1 year ago.
I am aware that the initial question is answered several times. Usually I know how to do it, so its more a bug fixing question instead of a general question. The code shows a cross which behaves as a toggle. If clicked another 3 elements appear, where the one on the middle gives me headache. I used a fontAwesome icon and can´t figure out why it will not center in this div element.
I am summon a CSS master which could solve my bug. ;)
<!-- fontawesome stylesheet https://fontawesome.com/ -->
<script src="https://kit.fontawesome.com/39094309d6.js" crossorigin="anonymous"></script>
<style>
html {
margin: auto;
width: 50%;
}
.modal-setting-toggle {
position: relative;
margin-top: 10px;
width:40px;
height: 40px;
border-radius: 10px;
background: #ecf0f3;
cursor: pointer;
box-shadow: 6px 6px 10px rgba(0, 0, 0, 0.1), -6px -6px 10px white;
}
.modal-setting-toggle::before, .modal-setting-toggle::after {
content: "";
background: #c3c2c7;
border-radius: 5px;
width: 20px;
height: 5px;
position: absolute;
left: 10px;
top: 18px;
transition: 0.2s ease;
z-index: 1;
}
.modal-setting-toggle::before {
transform: rotate(0deg);
}
.modal-setting-toggle::after {
transform: rotate(-90deg);
}
.modal-setting-toggle:hover::before {
transform: rotate(0deg);
background-color: #3498db;
}
.modal-setting-toggle:hover::after {
transform: rotate(-90deg);
background-color: #3498db;
}
.modal-setting-toggle.open::before {
transform: rotate(45deg);
background-color: #3498db;
}
.modal-setting-toggle.open::after {
transform: rotate(-45deg);
background-color: #3498db;
}
.modal-setting-toggle.open .modal-setting-button {
opacity: 1;
pointer-events: auto;
}
.modal-setting-toggle.open .modal-setting-button:first-of-type {
bottom: -50px;
background: url("https://bassets.github.io/cam.svg") no-repeat 50%/50% #ecf0f3;
}
.modal-setting-toggle.open .modal-setting-button:nth-of-type(2) {
bottom: -100px;
background: #ecf0f3;
justify-content: center;
align-items: center;
text-align: center;
transition-delay: 0.05s;
}
.modal-setting-toggle.open .modal-setting-button:last-of-type {
bottom: -150px;
background: url("https://bassets.github.io/music.svg") no-repeat 50% 45%/50% 45% #ecf0f3;
transition-delay: 0.1s;
}
.modal-setting-button {
width: 40px;
height: 40px;
border-radius: 10px;
cursor: pointer;
background: #ecf0f3;
position: absolute;
opacity: 0;
pointer-events: none;
box-shadow: inherit;
transition: 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28), 0.2s ease opacity, 0.2s cubic-bezier(0.08, 0.82, 0.17, 1) transform;
}
.modal-setting-button:hover {
transform: scale(1.1);
}
</style>
<section id="modal-setting" class="modal box-shadow">
<div style="float: right" class="modal-setting-toggle" onclick="this.classList.toggle('open')">
<div class="modal-setting-button"></div>
<div class="modal-setting-button"><i class="fas fa-link"></i></div>
<div class="modal-setting-button"></div>
</div>
</section>
Add display: flex to .modal-setting-toggle.open .modal-setting-button:nth-of-type(2) to make use of the align-items: center property.
html {
margin: auto;
width: 50%;
}
.modal-setting-toggle {
position: relative;
margin-top: 10px;
width: 40px;
height: 40px;
border-radius: 10px;
background: #ecf0f3;
cursor: pointer;
box-shadow: 6px 6px 10px rgba(0, 0, 0, 0.1), -6px -6px 10px white;
}
.modal-setting-toggle::before,
.modal-setting-toggle::after {
content: "";
background: #c3c2c7;
border-radius: 5px;
width: 20px;
height: 5px;
position: absolute;
left: 10px;
top: 18px;
transition: 0.2s ease;
z-index: 1;
}
.modal-setting-toggle::before {
transform: rotate(0deg);
}
.modal-setting-toggle::after {
transform: rotate(-90deg);
}
.modal-setting-toggle:hover::before {
transform: rotate(0deg);
background-color: #3498db;
}
.modal-setting-toggle:hover::after {
transform: rotate(-90deg);
background-color: #3498db;
}
.modal-setting-toggle.open::before {
transform: rotate(45deg);
background-color: #3498db;
}
.modal-setting-toggle.open::after {
transform: rotate(-45deg);
background-color: #3498db;
}
.modal-setting-toggle.open .modal-setting-button {
opacity: 1;
pointer-events: auto;
}
.modal-setting-toggle.open .modal-setting-button:first-of-type {
bottom: -50px;
background: url("https://bassets.github.io/cam.svg") no-repeat 50%/50% #ecf0f3;
}
.modal-setting-toggle.open .modal-setting-button:nth-of-type(2) {
bottom: -100px;
background: #ecf0f3;
justify-content: center;
align-items: center;
text-align: center;
transition-delay: 0.05s;
display: flex; /* ADD THIS */
}
.modal-setting-toggle.open .modal-setting-button:last-of-type {
bottom: -150px;
background: url("https://bassets.github.io/music.svg") no-repeat 50% 45%/50% 45% #ecf0f3;
transition-delay: 0.1s;
}
.modal-setting-button {
width: 40px;
height: 40px;
border-radius: 10px;
cursor: pointer;
background: #ecf0f3;
position: absolute;
opacity: 0;
pointer-events: none;
box-shadow: inherit;
transition: 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28), 0.2s ease opacity, 0.2s cubic-bezier(0.08, 0.82, 0.17, 1) transform;
}
.modal-setting-button:hover {
transform: scale(1.1);
}
<script src="https://kit.fontawesome.com/39094309d6.js" crossorigin="anonymous"></script>
<section id="modal-setting" class="modal box-shadow">
<div style="float: right" class="modal-setting-toggle" onclick="this.classList.toggle('open')">
<div class="modal-setting-button"></div>
<div class="modal-setting-button"><i class="fas fa-link"></i></div>
<div class="modal-setting-button"></div>
</div>
</section>

I have a nice image hover effect on desktop, but it gets stuck on hovered in mobile (Codepen included)

https://codepen.io/DubCoder/pen/poEQJap I really like this hover effect on desktop, but when I show my friends my site on mobile, they touch the image, and it enlarges/colorizes, but then it stays in that state, even after they touch it again. It only goes back to it's original black and white state after they scroll away from it.
I would like the photo to toggle between the two states each time you touch it on mobile. I'm not sure how to go about this. I'm sure there's a way to use media queries or JS to recognise when the user is on a mobile, and add/remove the colored state on click.
I think the fact there's pseudo-classes involved may make it trickier.
body {
background-color: beige
}
.item {
width: 50%;
position: relative;
left: 5rem;
top: 2rem;
filter: grayscale(100%);
transform: scale(0.8, 0.8) rotate(3deg);
transition: all 0.35s;
}
.polaroid {
background: #fff;
padding: 1rem;
box-shadow: 0 0.2rem 1.2rem rgba(0, 0, 0, 0.2);
}
.polaroid>img {
max-width: 100%;
height: auto;
}
.item .polaroid:before {
content: '';
position: absolute;
z-index: -1;
transition: all 0.35s;
}
.item .polaroid:before {
height: 20%;
width: 47%;
bottom: 0px;
box-shadow: 0 2.1rem 2rem rgba(0, 0, 0, 0.3);
}
.item:hover {
filter: none;
transform: scale(1, 1) rotate(0deg) !important;
transition: all 0.35s;
}
.item:hover .polaroid:before {
content: '';
position: absolute;
z-index: -1;
transform: rotate(0deg);
height: 90%;
width: 75%;
bottom: 0%;
box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.2);
transition: all 0.35s;
}
<div class="item">
<div class="polaroid">
<img src="https://i.imgur.com/5YVg9Ru.jpg" />
</div>
</div>
Consider making it focusable. It won't be a toggle by pressing just it, but it will still act natural as to what the user would expect and will be much easier to add.
You can do it by adding tabindex="0" to .item in the HTML markup. Then replace the two lines:
.item:hover {
.item:hover .polaroid:before {
with
.item:hover, .item:focus {
.item:hover .polaroid:before, .item:focus .polaroid:before {
This will apply the effect when it's focused too. You might want to add
outline: none
Inside the .item:hover, .item:focus class to remove the black outline on focus.
Your final results might be:
body {
background-color: beige
}
.item {
width: 50%;
position: relative;
left: 5rem;
top: 2rem;
filter: grayscale(100%);
transform: scale(0.8, 0.8) rotate(3deg);
transition: all 0.35s;
}
.polaroid {
background: #fff;
padding: 1rem;
box-shadow: 0 0.2rem 1.2rem rgba(0, 0, 0, 0.2);
}
.polaroid>img {
max-width: 100%;
height: auto;
}
.item .polaroid:before {
content: '';
position: absolute;
z-index: -1;
transition: all 0.35s;
}
.item .polaroid:before {
height: 20%;
width: 47%;
bottom: 0px;
box-shadow: 0 2.1rem 2rem rgba(0, 0, 0, 0.3);
}
.item:hover, .item:focus {
outline: none;
filter: none;
transform: scale(1, 1) rotate(0deg) !important;
transition: all 0.35s;
}
.item:hover .polaroid:before, .item:focus .polaroid:before {
content: '';
position: absolute;
z-index: -1;
transform: rotate(0deg);
height: 90%;
width: 75%;
bottom: 0%;
box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.2);
transition: all 0.35s;
}
<div class="item" tabindex="0">
<div class="polaroid">
<img src="https://i.imgur.com/5YVg9Ru.jpg" />
</div>
</div>
If you want a toggle, you'll need to use JS. I'm simply adding and removing a active class from the element on click and then using it in place of an event.
I removed the hover effect so you can see it better on PC.
function toggleClass(ele, className) {
if (ele.classList.contains(className)) {
ele.classList.remove(className);
} else {
ele.classList.add(className);
}
}
body {
background-color: beige
}
.item {
width: 50%;
position: relative;
left: 5rem;
top: 2rem;
filter: grayscale(100%);
transform: scale(0.8, 0.8) rotate(3deg);
transition: all 0.35s;
}
.polaroid {
background: #fff;
padding: 1rem;
box-shadow: 0 0.2rem 1.2rem rgba(0, 0, 0, 0.2);
}
.polaroid>img {
max-width: 100%;
height: auto;
}
.item .polaroid:before {
content: '';
position: absolute;
z-index: -1;
transition: all 0.35s;
}
.item .polaroid:before {
height: 20%;
width: 47%;
bottom: 0px;
box-shadow: 0 2.1rem 2rem rgba(0, 0, 0, 0.3);
}
.item.active {
outline: none;
filter: none;
transform: scale(1, 1) rotate(0deg) !important;
transition: all 0.35s;
}
.item.active .polaroid:before {
content: '';
position: absolute;
z-index: -1;
transform: rotate(0deg);
height: 90%;
width: 75%;
bottom: 0%;
box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.2);
transition: all 0.35s;
}
<div class="item" onclick="toggleClass(this, 'active')">
<div class="polaroid">
<img src="https://i.imgur.com/5YVg9Ru.jpg" />
</div>
</div>

<a> element styled button is scrolling down my web page

I've been trying to force my button to not scroll down/up to the linked element and just produce the button's animation without any success!
I've tried the jquery's preventDefault(among many other things) but this would not let the animation to actually work
Here is the code
Code in codepen
html,
body {
height: 120%;
background-color: gray;
}
a {
text-decoration: none;
}
a::-moz-focus-inner {
border: 0;
}
/*Buttons style; button_input is for the sepcial inputs*/
.button {
top-margin: 1rem;
}
.button_input {
width: 140px;
}
.male>span {
right: 30%;
position: absolute;
display: block;
width: 80px;
height: 80px;
}
.female>span {
left: 30%;
position: absolute;
display: block;
width: 80px;
height: 80px;
}
.bg {
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.2);
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
transition: all 0.2s linear;
}
.bg2 {
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.2);
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
transition: all 0.2s linear;
}
.icon::before,
.icon::after {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
display: block;
margin: auto;
border-radius: 2px;
content: "";
}
.male .icon::after {
background-repeat: no-repeat;
background-image: url("../images/man.png");
background-position: center;
}
.female .icon::after {
background-repeat: no-repeat;
background-image: url("../images/woman.png");
background-position: center;
}
.bg::after {
position: absolute;
top: -4.75rem;
left: -4.75rem;
display: block;
width: 15rem;
height: 15rem;
border: 4px solid #fff;
border-radius: 50%;
box-sizing: border-box;
content: "";
transform: scale(0.4);
opacity: 0;
}
.button:hover .bg {
background-color: rgba(255, 255, 255, 0.3)
}
.bg:target {
animation: push 1s ease-out;
transition: all 1s linear;
}
#male:target {
background-color: #003D79;
}
#female:target {
background-color: #003D79;
}
.bg:target::before,
.bg:target::after {
animation: wave 1s ease-in-out;
}
.bg:target::before {
animation-delay: 0.2s;
}
.bg:target::after {
animation-delay: 0.3s;
}
.bg2::after {
position: absolute;
top: -4.75rem;
left: -4.75rem;
display: block;
width: 15rem;
height: 15rem;
border: 4px solid #fff;
border-radius: 50%;
box-sizing: border-box;
content: "";
transform: scale(0.4);
opacity: 0;
}
.button:hover .bg2 {
background-color: rgba(255, 255, 255, 0.3)
}
.bg2:target {
animation: push 1s ease-out;
transition: all 1s linear;
}
.bg2:target::before,
.bg2:target::after {
animation: waves 1s ease-in-out;
}
.bg2:target::before {
animation-delay: 0.2s;
}
.bg2:target::after {
animation-delay: 0.3s;
}
#keyframes push {
15% {
transform: scale(0.75);
box-shadow: 0 0 1px rgba(0, 0, 0, 0.3)
}
75% {
transform: scale(1.1);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1)
}
100% {
transform: scale(1)
}
}
#keyframes wave {
10% {
opacity: 0.3
}
100% {
transform: scale(1);
opacity: 0
}
from {
background-color: #2EB4FF;
}
}
#keyframes waves {
10% {
opacity: 0.3
}
100% {
transform: scale(1);
opacity: 0
}
from {
background-color: #FF99CC;
}
}
/*Espacios para el td de la opción géneros */
table.table td.genders {
padding-top: 1%;
padding-bottom: 8%;
}
<table>
<tr>
<td align='center' colspan='3'>
<h5 class='StepTitle'>Partaker's Gender</h5>
</td>
</tr>
<tr>
<td align='center' class="genders">
<a class="button male" href="#male">
<span class="bg" id="male"></span>
<span class="symbol"></span>
</a>
<a class="button female" href="#female">
<span class="bg2" id="female"></span>
<span class="icon"></span>
</a>
</td>
</tr>
</table>
This scrolling behavior is baked into the :target pseudo selector, since the browser's default is to scroll the targeted id to the top of the window.
Using jQuery's toggleClass method would be a pretty simple solution. However, if you want to use pure CSS there are a couple workarounds. One is to place an absolutely positioned element and add the id for the element you're targeting to it.
A second option is to use the checkbox hack, where you use styled labels for a hidden checkbox instead.
Hope this helps!
html,
body {
height: 100%;
background-color: gray;
}
a {
text-decoration: none;
}
a::-moz-focus-inner {
border: 0;
}
table {
margin: 0 auto;
}
/*Buttons style; button_input is for the sepcial inputs*/
.button {
margin-top: 1rem;
}
.button_input {
width: 140px;
}
.male>span {
right: 30%;
position: absolute;
display: block;
width: 80px;
height: 80px;
}
.icon {
left: 30%;
position: absolute;
display: block;
width: 80px;
height: 80px;
}
.icon::before,
.icon::after {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
display: block;
margin: auto;
border-radius: 2px;
content: "";
}
.male .icon::after {
background-repeat: no-repeat;
background-image: url("../images/man.png");
background-position: center;
}
.female .icon::after {
background-repeat: no-repeat;
background-image: url("../images/woman.png");
background-position: center;
}
.bg::after {
position: absolute;
top: -4.75rem;
left: -4.75rem;
display: block;
width: 15rem;
height: 15rem;
border: 4px solid #fff;
border-radius: 50%;
box-sizing: border-box;
content: "";
transform: scale(0.4);
opacity: 0;
}
.button:hover .bg {
background-color: rgba(255, 255, 255, 0.3)
}
.bg2::after {
position: absolute;
top: -4.75rem;
left: -4.75rem;
display: block;
width: 15rem;
height: 15rem;
border: 4px solid #fff;
border-radius: 50%;
box-sizing: border-box;
content: "";
transform: scale(0.4);
opacity: 0;
}
.button:hover .bg2 {
background-color: rgba(255, 255, 255, 0.3)
}
#keyframes push {
15% {
transform: scale(0.75);
box-shadow: 0 0 1px rgba(0, 0, 0, 0.3)
}
75% {
transform: scale(1.1);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1)
}
100% {
transform: scale(1)
}
}
#keyframes wave {
10% {
opacity: 0.3
}
100% {
transform: scale(1);
opacity: 0
}
from {
background-color: #2EB4FF;
}
}
#keyframes waves {
10% {
opacity: 0.3
}
100% {
transform: scale(1);
opacity: 0
}
from {
background-color: #FF99CC;
}
}
/*Espacios para el td de la opción géneros */
table.table td.genders {
padding-top: 1%;
padding-bottom: 8%;
}
//checkbox hack
#toggle-male,
#toggle-female {
opacity: 0;
}
input[type=checkbox] {
opacity: 0;
}
label {
display: block;
width: 80px;
height: 80px;
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.2);
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
transition: all 0.2s linear;
cursor: pointer;
}
/* toggled state */
/* male animation */
#toggle-male:checked~.bg {
animation: push 1s ease-out;
transition: all 1s linear;
background-color: #003D79;
}
#toggle-male:checked~.bg::before,
#toggle-male:checked~.bg::after {
animation: waves 1s ease-in-out;
}
#toggle-male:checked~.bg::before {
animation-delay: 0.2s;
}
#toggle-male:checked~.bg1::after {
animation-delay: 0.3s;
}
/* female animations */
#toggle-female:checked~.bg2 {
animation: push 1s ease-out;
transition: all 1s linear;
background-color: #003D79;
}
#toggle-female:checked~.bg2::before,
#toggle-female:checked~.bg2::after {
animation: waves 1s ease-in-out;
}
#toggle-female:checked~.bg2::before {
animation-delay: 0.2s;
}
#toggle-female:checked~.bg2::after {
animation-delay: 0.3s;
}
<table>
<tr>
<td align='center' colspan='3'>
<h5 class='StepTitle'>Partaker's Gender</h5>
</td>
</tr>
<tr>
<td align='center' width="100px" class="genders">
<a class="button male" id="male">
<input type="checkbox" id="toggle-male">
<label for="toggle-male" class="bg"></label>
</a>
</td>
<td align='center' width="100px" class="genders">
<a class="button female" id="female">
<input type="checkbox" id="toggle-female">
<label for="toggle-female" class="bg2"></label>
</a>
</td>
</tr>
</table>
Edit:
Here's an example with jQuery:
$(document).ready(function() {
$('.bgs').on('click', function() {
$(this).toggleClass('animate background').toggleClass('animateAft');
if ($('.bgs').hasClass('animate background' || 'animateAft')) {
$('.bgs').not(this).removeClass('animate background').removeClass('animateAft');
}
})
});
html,
body {
height: 100%;
background-color: gray;
}
a {
text-decoration: none;
}
a::-moz-focus-inner {
border: 0;
}
table {
margin: 0 auto;
}
.button {
margin-top: 1rem;
}
.button_input {
width: 140px;
}
.icon {
left: 30%;
position: absolute;
display: block;
width: 80px;
height: 80px;
}
.icon::before,
.icon::after {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
display: block;
margin: auto;
border-radius: 2px;
content: "";
}
.male .icon::after {
background-repeat: no-repeat;
background-image: url("../images/man.png");
background-position: center;
}
.female .icon::after {
background-repeat: no-repeat;
background-image: url("../images/woman.png");
background-position: center;a
}
.bgs {
display: block;
width: 80px;
height: 80px;
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.2);
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
transition: all 0.2s linear;
cursor: pointer;
}
.bg:after,
.bg2:after {
position: absolute;
top: -4.75rem;
left: -4.75rem;
display: block;
width: 15rem;
height: 15rem;
border: 4px solid #fff;
border-radius: 50%;
box-sizing: border-box;
content: "";
transform: scale(0.4);
opacity: 0;
}
.animate {
animation: push 1s ease-out;
}
.background {
transition: background .4s ease;
background-color: #003D79;
}
.bg.animateAft:after,
.bg2.animateAft:after {
animation: waves 1s ease-in-out;
}
.bg.animateAft:before,
bg2.animateAft:before {
animation-delay: 0.2s;
}
.bg.animateAft:after,
.bg2.animateAft:after {
animation-delay: 0.3s;
}
#keyframes push {
15% {
transform: scale(0.75);
box-shadow: 0 0 1px rgba(0, 0, 0, 0.3)
}
75% {
transform: scale(1.1);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1)
}
100% {
transform: scale(1)
}
}
#keyframes wave {
10% {
opacity: 0.3
}
100% {
transform: scale(1);
opacity: 0
}
from {
background-color: #2EB4FF;
}
}
#keyframes waves {
10% {
opacity: 0.3
}
100% {
transform: scale(1);
opacity: 0
}
from {
background-color: #FF99CC;
}
}
/*Espacios para el td de la opción géneros */
table.table td.genders {
padding-top: 1%;
padding-bottom: 8%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td align='center' colspan='3'>
<h5 class='StepTitle'>Partaker's Gender</h5>
</td>
</tr>
<tr>
<td align='center' width="100px" class="genders">
<a class="button male" id="male">
<span id="toggle-male" class="bgs bg"></span>
</a>
</td>
<td align='center' width="100px" class="genders">
<a class="button female" id="female">
<span id="toggle-female" class="bgs bg2"></span>
</a>
</td>
</tr>
</table>
I sometimes fix this, by adding an invisible div, upper from your real target... and then target <a> to that invis div:
Like this:
<div id="BUBU" style="position: absolute; margin-top: -100px; display: none;"></div>
...
<span class="REAL-TARGET"></span>

How to make the slide down animation using css3 with display none to block

I was just wondering how could i add display: none and display: block to my animation with a ease effect.
HTML
<div class="floating-vociebox">
<a>New updates</a>
</div>
Any help would be appreciated
DEMO
I have tried to start from display:none;. I have three variants to add movement and fade-in by CSS3 and jQuery. Which one is more like what you need?
$( document ).ready(function(){
$('.variant-1').fadeIn( 3000 ).addClass('animate-1');
$('.variant-2').css('display','block').delay( 0 ).queue(function(){
$(this).addClass('animate-2').dequeue();
});
$('.variant-3').addClass('visible').delay( 0 ).queue(function(){
$(this).addClass('animate-2').dequeue();
});
});
.floating-vociebox {
background-color: blue;
width: 120px;
height: 30px;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.19);
border-radius: 4px;
position: fixed;
top: 100px;
transform: translateY(-90px);
display: none;
}
.variant-1 {
left: 10px;
transition: background-color 0.3s, transform 3s ease-in-out;
}
.variant-2 {
left: 150px;
}
.variant-3 {
left: 290px;
}
.variant-2,
.variant-3 {
opacity: 0;
transition: background-color 0.3s, opacity 3s ease-in, transform 3s ease-in-out;
}
.visible {
display: block;
}
.animate-1 {
transform: translateY(0);
}
.animate-2 {
opacity: 1;
transform: translateY(0);
}
.floating-vociebox:hover {
background-color: darkblue;
}
.floating-vociebox a {
cursor: pointer;
display: block;
text-align: center;
line-height: 30px;
font-size: 14px;
font-weight: 500;
color: #fff;
}
<div class="floating-vociebox variant-1">
<a>Variant 1</a>
</div>
<div class="floating-vociebox variant-2">
<a>Variant 2</a>
</div>
<div class="floating-vociebox variant-3">
<a>Variant 3</a>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
https://jsfiddle.net/glebkema/gcg7f4pj/

I can't get the button to center over the image when hovered

when the image is hovered on, a button appears; the button is towards the left and I need to get it centered in the middle. I'm using HTML5, CSS3 and bootsrap v3.3.4. Everything works properly except for the button not centering. What am I missing? Thanks in advance for the help :)
<div class="row">
<div class="col-sm-3">
<figure class="wow fadeInLeft animated portfolio-item" data-wow-duration="500ms" data-wow-delay="0ms">
<figcaption>
<h4>
<a href="#">
Test
</a>
</h4>
<p>
test
</p>
</figcaption>
<div class="img-wrapper">
<img src="image1.jpg" class="img-responsive" alt="title" >
<div class="overlay">
<div class="buttons">
<a target="_blank" href="">Discover</a>
</div>
</div>
</div>
<figcaption>
<h4>
<a href="#">
test
</a>
</h4>
<p>
test
</p>
</figcaption>
</figure>
</div>
CSS
figure {
background: #fff;
margin-bottom: 45px;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.04), 0 2px 10px 0 rgba(0, 0, 0, 0.06);
}
figure .img-wrapper {
position: relative;
overflow: hidden;
}
figure img {
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
-webkit-transition: -webkit-transform 400ms;
transition: transform 400ms;
}
figure:hover img {
-webkit-transform: scale3d(1.2, 1.2, 1);
transform: scale3d(1.2, 1.2, 1);
}
figure:hover .overlay {
opacity: 1;
}
figure:hover .overlay .buttons a {
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
figure .overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
padding: 10px;
text-align: center;
background: rgba(0, 0, 0, 0.7);
opacity: 0;
-webkit-transition: opacity 400ms;
transition: opacity 400ms;
}
figure .overlay a {
display: inline-block;
color: #fff;
padding: 10px 23px;
line-height: 1;
border: 1px solid #fff;
border-radius: 0px;
margin: 4px;
-webkit-transform: scale3d(0, 0, 0);
transform: scale3d(0, 0, 0);
-webkit-transition: all 400ms;
transition: all 400ms;
}
figure .overlay a:hover {
text-decoration: none;
}
figure .overlay:hover a {
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
figure .buttons {
position: absolute;
top: 45%;
left: 24%;
}
figure figcaption {
padding: 20px 25px;
margin-top: 0;
color: #666;
}
figure figcaption h4 {
margin: 0;
}
figure figcaption h4 a {
color: #02bdd5;
}
figure figcaption p {
font-size: 16px;
margin-bottom: 0;
margin-top: 5px;
}
If you'll use flexbox, this will be easier to achieve (even with bootstrap's responsive design), and will be supported by all modern browsers
In order to do that, change your css as follows:
figure .buttons {
/* remove all styles */
}
figure .overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
padding: 10px;
text-align: center;
background: rgba(0, 0, 0, 0.7);
opacity: 0;
-webkit-transition: opacity 400ms;
transition: opacity 400ms;
/* Added styles: */
display: flex;
justify-content: center;
align-items: center;
}
(This will also work if you add more buttons to your .buttons element)
Here's a Codepen with a working demo