My animation properties are not working simultaneously - css

I am trying a simple animation of div which animates when page loads. Below you can see the GIF of the animation.
Here is the code
#keyframes newActivity{
to{
position: fixed;
z-index: 100;
top: 18%;
left: 10%;
width:70%;
height:80%;
}
}
.div:first-child {
animation-name:newActivity;
animation-duration:5s;
}
div {
width: 290px;
height:200px;
float:left;
margin-right: 10px;
margin-bottom: 10px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 5px rgba(0, 0, 0, 0.06);
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 5px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 5px rgba(0, 0, 0, 0.06);
background-color:red;
border: 1px solid #BCBCBC;
overflow:hidden;
z-index:-10;
}
<div class='div'></div>
You can see that first it increases the width and adjust position and increase the height(Without animating it). Why is this happening? I want to animate all of these properties simultaneously.

This is happening because you have set the to height as a percentage, but height percentages are inherited; they only work when the parent element has a declared height.
Only the viewport has an inherent height set, so if you want to use height: 80% on your div, then you need to also set html, body { height: 100%; } in your CSS. The html element is the child of the viewport, and body is the child of html. This way, your div's height: 80%; can inherit all the way up through body and html to the viewport. See this example:
html, body {
height: 100%;
}
#keyframes newActivity {
to {
position: fixed;
z-index: 100;
top: 18%;
left: 10%;
width: 70%;
height: 80%;
}
}
.div:first-child {
animation-name: newActivity;
animation-duration: 5s;
}
div {
width: 290px;
height: 200px;
float: left;
margin-right: 10px;
margin-bottom: 10px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 5px rgba(0, 0, 0, 0.06);
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 5px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 5px rgba(0, 0, 0, 0.06);
background-color: red;
border: 1px solid #BCBCBC;
overflow: hidden;
z-index: -10;
}
<div class="div"></div>
P.S. position is not a valid animation property. See a list of valid properties here on the Mozilla Developer Network.
P.P.S. if you want the animation to retain its state at the end, you can use animation-fill-mode: forwards;.

Related

Customize CSS code based on selected woocommerce attribute

I added CSS code to create frames around woocommerce product images.
.woocommerce-product-gallery__image img {
background-color: #fff;
width: 100%;
max-width: 100%;
height: auto;
padding: 20px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0
rgba(0, 0, 0, 0.19);
}
It works with a simple product.
However, I don't know what to do with a variable product. Indeed, I want the frame to appear only when an attribute is selected.
For example, a variable product with 2 attributes:
-black
-white
I would like me to apply the following code for the white attribute
.woocommerce-product-gallery__image img {
background-color: #fff;
width: 100%;
max-width: 100%;
height: auto;
padding: 20px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0
rgba(0, 0, 0, 0.19);
}
And this one for the black attribute.
.woocommerce-product-gallery__image img {
background-color: #000;
width: 100%;
max-width: 100%;
height: auto;
padding: 20px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0
rgba(0, 0, 0, 0.19);
}
I know that we can add images by variations but I want to work with CSS code, which is easier to manage.
Is there a specific class for the attribute? Should I use a php function?
Thank you all!

no mixin named transition-duration

I am migrating from Bootstrap 3 to Bootstrap 4. So I am converting the LESS files to SCSS. I used this to convert my files.
However, the error I get is: no mixin named transition-duration
charts.less
.mini-charts-item {
-moz-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
position: relative;
margin-bottom: 30px;
&:before {
.transition(width);
.transition-duration(500ms);
.backface-visibility(hidden);
content: "";
width: 113px;
height: 100%;
background: rgba(0,0,0,0.1);
position: absolute;
left: 0;
top: 0;
}
}
charts.scss
.mini-charts-item {
-moz-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
position: relative;
margin-bottom: 30px;
&:before {
content: "";
width: 113px;
height: 100%;
background: rgba(0,0,0,0.1);
position: absolute;
left: 0;
top: 0;
#include transition(width);
#include transition-duration(500ms);
#include backface-visibility(hidden);
}
}
'transition-duration' is not a mixin. it's a built-in css property for animations. You can use it with no need to include it. For more info you can refer to [this link].1

How to create a popup with partial left border?

I have to create this modal with same style:
This is what I have right now:
.notification {
position: fixed;
top: 32px;
right: 32px;
width: 460px;
height: 150px;
border-radius: 36px;
box-shadow: 0 7px 8px -4px rgba(0, 0, 0, 0.2), 0 5px 22px 4px rgba(0, 0, 0, 0.12), 0 12px 17px 2px rgba(0, 0, 0, 0.14);
background-color: white;
z-index: 999999;
}
.notification > .border {
background-color: #3fb4e4;
margin-left: 20px;
border-radius: 36px;
width: 34px;
height: 150px;
}
<div class="notification"><div class="border"></div>Hello</div>
But I cant find a way to create the blue border on the left.
Use multiple background like below:
.notification {
border-radius: 36px;
padding:50px;
width:100px;
box-shadow:
0 7px 8px -4px rgba(0, 0, 0, 0.2),
0 5px 22px 4px rgba(0, 0, 0, 0.12),
0 12px 17px 2px rgba(0, 0, 0, 0.14);
/* Relevant code*/
border:3px solid transparent; /* Control the thickness*/
background:
/* Cover only the padding area*/
linear-gradient(#fff,#fff) padding-box,
/* Cover the border area: adjust the 50px to control the size */
linear-gradient(to right, #3fb4e4 50px,transparent 0) border-box;
}
<div class="notification">Hello</div>
Another syntax where you can control the size outside the gradient:
.notification {
border-radius: 36px;
padding:50px;
width:100px;
box-shadow:
0 7px 8px -4px rgba(0, 0, 0, 0.2),
0 5px 22px 4px rgba(0, 0, 0, 0.12),
0 12px 17px 2px rgba(0, 0, 0, 0.14);
/* Relevant code*/
border:3px solid transparent; /* Control the thickness*/
background:
/* Cover only the padding area*/
linear-gradient(#fff,#fff) padding-box,
/* Cover the border area */
linear-gradient(#3fb4e4,#3fb4e4) left border-box no-repeat;
background-size:50px 100%;
transition:0.6s;
}
.notification:hover {
background-size: 100px 100%;
}
<div class="notification">Hello</div>
Why not just add a border on the container itself:
.notification {
position: fixed;
top: 32px;
right: 32px;
width: 460px;
height: 150px;
border-radius: 36px;
box-shadow: 0 7px 8px -4px rgba(0, 0, 0, 0.2), 0 5px 22px 4px rgba(0, 0, 0, 0.12), 0 12px 17px 2px rgba(0, 0, 0, 0.14);
background-color: white;
z-index: 999999;
border-left: 3px solid #3fb4e4;
}

is it possible to do non-overlapping shadows?

If you put your mouse over the pill-shaped thing, It'll move over the circle (what I want to happen), but the shadow of the circle will remain visible.
I want the shadows to not affect each other, but still be transparent.
body {
background-color: aqua;
}
#circle1, #circle2 {
position: relative;
float: left;
height: 50px;
width: 50px;
border-radius: 25px;
margin-left: 8px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
z-index: 0;
background-color: white;
}
#pill1, #pill2 {
position: relative;
float: left;
height: 50px;
width: 100px;
border-radius: 25px;
margin-left: 8px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
z-index: 1;
background-color: white;
}
#pill2 {
box-shadow: 0 4px 8px 0 rgba(180, 180, 180, 1), 0 6px 20px 0 rgba(200, 200, 200, 1);
}
#circle2 {
box-shadow: 0 4px 8px 0 rgba(180, 180, 180, 1), 0 6px 20px 0 rgba(200, 200, 200, 1);
}
#keyframes animation {
0% {right: 0px;}
100% {right: 58px;}
}
#pill1:hover, #pill2:hover {
animation: animation 0.5s linear forwards;
}
<div id="circle1"></div>
<div id="pill1"></div>
<div id="circle2"></div>
<div id="pill2"></div>
I forgot to mention something, it's supposed to be an animation. I put it in here as a transition but it wasn't working. I just fixed it, so it's now an animation.
The one on the right is what I want to happen, but that is max opacity.
You may remove the shadow on hover of the circle and make its z-index higher than the pill to catch its hover state:
body {
background-color: aqua;
}
#circle {
position: relative;
float: left;
height: 50px;
width: 50px;
border-radius: 25px;
margin-left: 8px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
z-index: 2;
background-color: white;
}
#pill {
position: relative;
float: left;
height: 50px;
width: 100px;
border-radius: 25px;
margin-left: 8px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
z-index: 1;
background-color: white;
}
#circle:hover + #pill, #pill:hover {
right: 58px;
}
#circle:hover {
box-shadow:none;
}
/*Added this to avoid the issue of hovering only the pill and not the circle*/
#circle:hover::after {
content:"";
position:absolute;
top:0;
bottom:0;
left:0;
width:100px;
}
<div id="circle"></div>
<div id="pill"></div>
UPDATE
By the way you can simplify your code like this:
I also included the transition
body {
background-color: aqua;
}
#circle {
position: relative;
height: 50px;
width: 50px;
border-radius: 25px;
margin-left: 8px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
background-color: white;
transition:all 0.5s;
}
#circle:before {
content:"";
position: absolute;
top:0;
left:80px;
height: 100%;
width: 100px;
border-radius: 25px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
background-color: white;
transition:all 0.5s;
}
#circle:hover::before {
left:0;
}
#circle:hover {
box-shadow:none;
}
/*Added this to avoid glitchs*/
#circle:after {
content:"";
position:absolute;
top:0;
bottom:0;
left:0;
width:200px;
}
#keyframes animation {
0% {left: 80px;}
100% {left: 0;}
}
<div id="circle"></div>

Apply gradient on image

Here's a JsFiddle.
I have an transformed image and I would like to add a gradient (black to transparant) on it.
HTML :
<div class="contentwrap">
<div class="perspectiveDiv">
<img src="http://image.noelshack.com/fichiers/2014/34/1408372755-black-card.png" class="img" />
</div>
</div>
CSS :
.contentwrap {
margin: 0 auto;
max-width: 600px;
height: 100%;
display: table;
padding-top: 150px;
}
.perspectiveDiv{
perspective:750px;
position: relative;
left: 0;
top: 0;
}
.img{
position: absolute;
top: -152px;
left: 25px;
transform: rotateX(60deg);
max-width: 250px;
-webkit-box-shadow: 0 8px 6px -6px rgba(0, 0, 0, 0.8);;
-moz-box-shadow: 0 8px 6px -6px rgba(0, 0, 0, 0.8);;
box-shadow: 0 60px 45px -20px rgba(0, 0, 0, 0.8);;
-moz-border-radius: 15px;
border-radius: 16px;
background: linear-gradient(to bottom, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
}
Here is the kind of result that I need (made with photoshop) :
I found how to apply a gradient on a background image, but not a standard image...
Is it possible to do what I need ?
Can you help me to do it ? It could be very simple but I'm a beginner and I didn't manage to do it...

Resources