Problem with making a background animation responsive - css

I built an animation for my background but is not responsive and I don't know how to make it.
I used Bootstrap 4 and CSS as my main design resources.
The CSS I sued as follows:
/* Animation GLitch */
.animation {
position: relative;
width: 100%;
height: 100vh;
background: url("https://images.unsplash.com/photo-1487174244970-cd18784bb4a4?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2252&q=80");
max-width: 100%;
max-height: 100%;
margin: 0 auto;
overflow: hidden;
}
.animation:before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url("https://images.unsplash.com/photo-1487174244970-cd18784bb4a4?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2252&q=80");
opacity: 0.5;
mix-blend-mode: hard-light;
display: block;
}
.animation:hover:before {
animation: animate 0.2s linear infinite;
}
#keyframes animate {
0% {
background-position: 0 0;
filter: hue-rotate(0deg);
}
10% {
background-position: 5px 0;
}
20% {
background-position: -5px 0;
}
30% {
background-position: 15px 0;
}
40% {
background-position: -5px 0;
}
50% {
background-position: -25px 0;
}
60% {
background-position: -50px 0;
}
70% {
background-position: 0 -20px;
}
80% {
background-position: -60px -20px;
}
81% {
background-position: 0 0;
}
100% {
background-position: 0 0;
filter: hue-rotate(360deg);
}
}
The animation consists of 2 same pictures that create this glitch effect but I don't know how to make it responsive.
The snippest it is working here:
https://codepen.io/Jakub41/pen/abbwxWb
I tried to use the sizing but it is modifying my effect I would like to keep the same effect on all screens

I do not quite understand in which way you want it to be responsive but try adding these lines after background: url(...) both times:
background-repeat: no-repeat;
background-size: cover;
Look here for more information about the background-size property.
Also the second answer of this question might interest you.

Related

Why is my sprite sheet animation sliding?

Trying to implement a sprite sheet animation via css. I have followed this example
https://codepen.io/SitePoint/pen/zxXrzP
However, my animation is sliding vertically and I can not understand why. Any input appreciated.
.parent {
position: relative;
width: 70%;
margin: -10% auto 0 auto;
/* positioning tweak */
}
.parent:before {
content: "";
display: block;
padding-top: 61.37%;
}
.ryu {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-image: url("http://dev.froststudio.se/wp-content/uploads/2020/06/frostcell_v03.png");
background-size: 100%;
animation: sprite 4s steps(79) forwards;
}
#keyframes sprite {
from {
background-position: 0 0%;
}
to {
background-position: 0 100%;
}
}
http://dev.froststudio.se
Cheers,

CSS clip-path breaks pseudo ::before element stack order

I'm trying to create a frosted glass effect on a non-rectangular element but it's not working out. I'm experiencing an odd issue that I can't seem to wrap my head around...
The frosted glass effect is easy to accomplish by setting a fixed background-image on the document body, adding a partially transparent background color to the element and creating a ::before pseudo element with the same fixed background-image and applying a blur filter. Like so:
body {
background: url(bg-lanterns.jpg) 0 / cover fixed;
}
main {
position: relative;
margin: 1rem auto;
padding: 1rem;
height: 600px;
width: 800px;
background: rgba(255,255,255,0.7);
}
main::before {
content: '';
z-index: -1;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: url(bg-lanterns.jpg) 0 / cover fixed;
filter: blur(10px);
}
Creating a non-rectangular element is also easy by using clip-path like this:
main {
position: relative;
margin: 1rem auto;
padding: 1rem;
height: 600px;
width: 800px;
background: rgba(255,255,255,0.7);
clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
}
But trying to combine these two effects breaks the stacking order and causes the ::before element to appear above the white background.
I get the same result in Chrome and Firefox so I'm wondering if this is the expected behavior and I'm simply doing something wrong... Can anybody shed some light on what is happening here?
Here's a live demo:
body {
background: url(https://i.imgur.com/y1TH8fR.jpg) 0 / cover fixed;
}
main {
position: relative;
margin: 1rem auto;
padding: 1rem;
height: 600px;
width: 800px;
background: rgba(255,255,255,0.7);
clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
}
main::before {
content: '';
z-index: -1;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
padding: 1rem;
background: url(https://i.imgur.com/y1TH8fR.jpg) 0 / cover fixed;
filter: blur(10px);
}
<main></main>
According to the specification for clip-path:
A computed value of other than none results in the creation of a stacking context [CSS21] the same way that CSS opacity [CSS3COLOR] does for values other than 1.
I managed to achieve the desired effect by adding the white color to an ::after pseudo element and clipping both pseudo elements instead of the element itself.
body {
background: url(https://i.imgur.com/y1TH8fR.jpg) 0 / cover fixed;
}
main {
position: relative;
margin: 1rem auto;
height: 600px;
width: 800px;
display: flex;
flex-flow: column nowrap;
align-content: center;
align-items: center;
justify-content: center;
}
main::before,
main::after {
content: '';
z-index: -1;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
}
main::before {
background: url(https://i.imgur.com/y1TH8fR.jpg) 0 / cover fixed;
filter: blur(10px);
}
main::after {
background: rgba(255,255,255,0.7);
}
<main> <span> test </span> </main>

CSS responsive sprite animation

I have the following codepen:
http://codepen.io/AlexanderWeb00/pen/GWprqx
I am trying to make it look like a gif so that I can pause it on hover.
However the result is not as expected: it almost looks like a vertical slider but it should only behave like a gif. It needs to be responsive which it is at the moment.
It should show one full t-shirt at the time
body {
padding: 0;
text-align: center;
}
.parent {
position: relative;
width: 70%;
margin: -10% auto 0 auto; /* positioning tweak */
}
.parent:before {
content: "";
display: block;
padding-top: 60%;
}
.children {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: url('http://imageshack.com/a/img922/8632/ME6qgO.png') no-repeat 0 0%;
background-size: 100%;
animation: sprite 5s steps(5) infinite;
}
#keyframes sprite {
from { background-position: 0 0%; }
to { background-position: 0 100%; }
}

CSS3 animation/keyframes, transforming with vw in IE11 issues

I'm animating an element across a screen, but in IE11, weird things are happening. I'm in development, so I can't share the live code. But I created a fiddle to replicate the problem.
Basically, when I use viewport width aka vw with transform:translateX(); inside a #keyframes to use in an animation, IE11 doesn't reflect the width of the viewport in the animation.
So the Fiddle I created takes an element that is positioned in the center of the viewport:
starts it at the left edge of the screen with half of the element
appearing
moves to the center of the viewport, pauses
and then moves to the right edge of the viewport, with half the element off of the screen
Fiddle: https://jsfiddle.net/Bushwazi/7xe0wy8z/4/
In the website I'm working on, IE11 animates the element as if the
page were 10 times wider
In the fiddle, the animation runs in reverse
and never makes it to the edge of the page.
So in both cases, IE11 isn't using the correct width for vw inside CSS animations.
HTML:
<!--
The animation on the red block should start half on the screen, pause at the center of the screen and then finish by pausing at the edge of the screen, half of the box off of the screen
-->
<article>
<p>IE11 weirdness when transforming vw inside keyframes</p>
<strong><span>BLOCK</span></strong>
</article>
CSS:
* {
margin: 0;
padding: 0;
}
#-webkit-keyframes movee {
0% {
-webkit-transform: translateX(-50vw);
transform: translateX(-50vw)
}
10% {
-webkit-transform: translateX(-50vw);
transform: translateX(-50vw)
}
40% {
-webkit-transform: translateX(0vw);
transform: translateX(0vw)
}
60% {
-webkit-transform: translateX(0vw);
transform: translateX(0vw)
}
90% {
-webkit-transform: translateX(50vw);
transform: translateX(50vw)
}
100% {
-webkit-transform: translateX(50vw);
transform: translateX(50vw)
}
}
#keyframes movee {
0% {
-webkit-transform: translateX(-50vw);
transform: translateX(-50vw)
}
10% {
-webkit-transform: translateX(-50vw);
transform: translateX(-50vw)
}
40% {
-webkit-transform: translateX(0vw);
transform: translateX(0vw)
}
60% {
-webkit-transform: translateX(0vw);
transform: translateX(0vw)
}
90% {
-webkit-transform: translateX(50vw);
transform: translateX(50vw)
}
100% {
-webkit-transform: translateX(50vw);
transform: translateX(50vw)
}
}
body {
background-color: #eee;
background-image: -webkit-linear-gradient(left, black 50%, transparent 50.01%);
background-image: linear-gradient(90deg, black 50%, transparent 50.01%);
background-size: 20% 100%;
background-position: 0 0;
font-family: sans-serif;
height: 100vh;
}
article {
position: relative;
height: 100%;
width: 100%;
display: block;
}
p {
width: 100%;
background: #FFF;
text-align: center;
padding: 1em 0;
}
strong {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
height: 100px;
width: 100px;
background: red;
border: blue solid 3px;
position: absolute;
top: 50%;
left: 50%;
box-sizing: border-box;
text-align: center;
margin: -50px 0 0 -50px;
-webkit-animation: movee 5.0s linear infinite 0.0s;
animation: movee 5.0s linear infinite 0.0s;
}
According to caniuse:
In IE 10 and 11, using vw units with 3D transforms causes unexpected behavior
Although 2D & 3D transforms are different, it is likely that they are handled by simliar methods within a browser. So I would say that VW/VH/VMAX/VMIN are not supported in IE11 for transitions.
Is there any reason you don't want to use % ?
Like this:
* {
margin: 0;
padding: 0;
}
#-webkit-keyframes movee {
0% {
left: -1%;
}
10% {
left: -1%;
}
40% {
left: 50%;
}
60% {
left: 50%;
}
90% {
left: 101%;
}
100% {
left: 101%;
}
}
#keyframes movee {
0% {
left: -1%;
}
10% {
left: -1%;
}
40% {
left: 50%;
}
60% {
left: 50%;
}
90% {
left: 101%;
}
100% {
left: 101%;
}
}
body {
background-color: #eee;
background-image: -webkit-linear-gradient(left, black 50%, transparent 50.01%);
background-image: linear-gradient(90deg, black 50%, transparent 50.01%);
background-size: 20% 100%;
background-position: 0 0;
font-family: sans-serif;
height: 100vh;
}
article {
border: thin dotted green;
position: relative;
height: 100%;
width: 100%;
display: block;
}
p {
width: 100%;
background: #FFF;
text-align: center;
padding: 1em 0;
}
strong {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
height: 100px;
width: 100px;
background: red;
border: blue solid 3px;
position: absolute;
top: 50%;
left: 50%;
box-sizing: border-box;
text-align: center;
margin: -50px 0 0 -50px;
-webkit-animation: movee 5.0s linear infinite 0.0s;
animation: movee 5.0s linear infinite 0.0s;
}
<!--
The animation on the red block should start half on the screen, pause at the center of the screen and then finish by pausing at the edge of the screen, half of the box off of the screen
-->
<article>
<p>IE11 weirdness when transforming vw inside keyframes</p>
<strong><span>BLOCK</span></strong>
</article>
One posibility would be to use transform as percentages.
Since you want the amout of the transform to be 100vw, lets set an extra element with a width of 100vw. Now, the transform on this element is just 100%.
I had to use negative offsets to avoid the appearance of an undesired horizontal scrollbar
* {
margin: 0;
padding: 0;
}
#keyframes movee {
0% {
transform: translateX(-100%)
}
10% {
transform: translateX(-100%)
}
40% {
transform: translateX(-50%)
}
60% {
transform: translateX(-50%)
}
90% {
transform: translateX(0%)
}
100% {
transform: translateX(0%)
}
}
body {
background-color: #eee;
background-image: linear-gradient(90deg, black 50%, transparent 50.01%);
background-size: 20% 100%;
background-position: 0 0;
height: 100vh;
}
article {
position: relative;
height: 100%;
width: 100%;
display: block;
}
p {
width: 100%;
background: #FFF;
text-align: center;
padding: 1em 0;
}
.base {
width: 100vw;
animation: movee 5.0s linear infinite 0.0s;
top: 50%;
position: absolute;
height: 100px;
}
strong {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
height: 100px;
width: 100px;
background: red;
border: blue solid 3px;
position: absolute;
right: 0px;
top: 0px;
box-sizing: border-box;
text-align: center;
margin: -50px 0 0 -50px;
}
<article>
<p>IE11 weirdness when transforming vw inside keyframes</p>
<div class="base">
<strong><span>BLOCK</span></strong>
</div>
</article>

CSS3-After-Element-Transformation not working cross browser?

i think my implementation of an animated hexagon has several cross-browser-problems:
http://jsbin.com/mojavowapi/1/edit?css,output
.hexagon {
position: relative;
width: 173px;
height: 300px;
background-image: url(https://live.tlprod.de/temp/glas.jpg);
background-size: auto 100%;
background-position: 50% 50%;
transition: all 2s linear;
margin-left: auto;
margin-right: auto;
}
.hexagon:after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2;
background: inherit;
}
.hexLeftBox, .hexRightBox {
overflow: hidden;
transform: scaleY(1.6) rotate(-45deg);
background: inherit;
top: 27.9%;
position: absolute;
display: inline-block; /* let the block get the width of the containing image */
z-index: 1;
height: 44%;
}
.hexLeft, .hexRight {
width: auto;
height: 100%; /* get full height of parent element, set width to aspect ratio 1:1 */
}
.hexLeftBox {
transform: scaleY(1.6) rotate(-45deg) translate(-35.5%,-35.5%);
}
.hexRightBox {
right: 0;
transform: scaleY(1.6) rotate(-45deg) translate(35.5%,35.5%);
}
.hexLeftBox:after, .hexRightBox:after {
content: "";
position: absolute;
width: 142%;
height: 142%;
transform: rotate(45deg) scaleY(1) scaleX(1.6) translate(-50%,0%);
transform-origin: 0 0;
background: inherit;
transition: all 2s linear;
}
.hexLeftBox:after {
background-position: -7% top;
}
.hexRightBox:after {
background-position: 107% top;
}
.hexagon:hover {
width: 300px;
height: 350px;
}
.hexagon:hover .hexLeftBox:after {
background-position: -35% top;
}
.hexagon:hover .hexRightBox:after {
background-position: 135% top;
}
.hexagon2 {
width: 300px;
height: 350px;
margin-top: 40px;
}
.hexagon2 .hexLeftBox:after {
background-position: -35% top;
}
.hexagon2 .hexRightBox:after {
background-position: 135% top;
}
In this example the above hexagon changes on hover to the -same- size as the other loaded with.
In Chrome 50 the background image of the after-elements disappear AND the aspect ratio crashes
In IE 11 only the aspect ratio of the edges crashes
In Firefox 46 all works fine
..but the funny thing: In all Browser the second static version with the same values as the hover is working fine.
Are there some problems known and fixable?
The crashed aspect ratio is a webkit-optimizing-issue.
It could be fixed only with switching to a javascript-animation with forcing the rerendering via:
$('body').css('display', 'table').height();
$('body').css('display', 'block');
And with jQuery you can do this in the progress-Parameter of the animate()-function.
Switching to a javascript-animation also eleminates the disappearing after-elements.

Resources