img not stretching to wrappers height and width - html

I'd like to have a wavy background on top of my regular background but the image is not stretching all the way out. It has to be position absolute (otherwise it's interfering with my navigation and moves it down by the height of the img). JSFiddle. I already tried object-fit: fill which also didn't work. Thanks in advance
My code:
* {
margin: 0;
padding: 0;
font-family: helvetica;
}
body {
height: 5000px;
}
#background {
position: absolute;
width: 100%;
height: 100%;
object-fit: contain;
object-position: ;
opacity: 15%;
}
#navwrapper {
background: linear-gradient(250deg, #0061ff, #60efff);
background-size: 400% 400%;
-webkit-animation: AnimationName 10s ease infinite;
-moz-animation: AnimationName 10s ease infinite;
animation: AnimationName 10s ease infinite;
height: 100vh;
}
#-webkit-keyframes AnimationName {
0% {
background-position: 0% 7%
}
50% {
background-position: 100% 94%
}
100% {
background-position: 0% 7%
}
}
#-moz-keyframes AnimationName {
0% {
background-position: 0% 7%
}
50% {
background-position: 100% 94%
}
100% {
background-position: 0% 7%
}
}
#keyframes AnimationName {
0% {
background-position: 0% 7%
}
50% {
background-position: 100% 94%
}
100% {
background-position: 0% 7%
}
}
<nav id="navwrapper">
<div id="background"><img src="https://i.postimg.cc/RZzwCTQz/Zeichenfla-che-92.png"></div>
</nav>

Instead of applying css to #background apply it in #background img thats where you want to change object fit property.
replace this
#background {
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
object-position: ;
opacity: 15%;
}
with this
#background img{
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
opacity: 15%;
}
You can check the output below
* {
margin: 0;
padding: 0;
font-family: helvetica;
}
body {
height: 5000px;
}
#background img {
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
object-position: ;
opacity: 15%;
}
#navwrapper {
background: linear-gradient(250deg, #0061ff, #60efff);
background-size: 400% 400%;
-webkit-animation: AnimationName 10s ease infinite;
-moz-animation: AnimationName 10s ease infinite;
animation: AnimationName 10s ease infinite;
height: 100vh;
}
#-webkit-keyframes AnimationName {
0% {
background-position: 0% 7%
}
50% {
background-position: 100% 94%
}
100% {
background-position: 0% 7%
}
}
#-moz-keyframes AnimationName {
0% {
background-position: 0% 7%
}
50% {
background-position: 100% 94%
}
100% {
background-position: 0% 7%
}
}
#keyframes AnimationName {
0% {
background-position: 0% 7%
}
50% {
background-position: 100% 94%
}
100% {
background-position: 0% 7%
}
}
<nav id="navwrapper">
<div id="background"><img src="https://i.postimg.cc/RZzwCTQz/Zeichenfla-che-92.png"></div>
</nav>

Use this property
#background{
background:url(...);
background-position: center !important;
background-size: cover !important;
background-repeat: no-repeat;
height: 500px;
width:100%
}

You can just set width and height to 100% for an image that it should all space of container:
#background img {
width: 100%;
height: 100%;
}

Related

CSS Positioning: Content that should be below the fold is appearing above the fold

I am trying to build a page that is divided into above-the-fold and below-the-fold sections to give the viewer an impression of going undersea. I've run into a stumbling block, because something just refuses to click in my brain when it comes to the concepts of CSS positioning.
Ultimately, I am trying to add another section below the fold where I can add content, but want the above water scene to stay full width. Currently, the content I want to appear below the fold is rendering in the above the fold section.
body {
background: #90caf9;
}
.above-water {
height: 100vh;
width: 100vw;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: 0;
}
.wave {
position: absolute;
width: 100%;
height: 220px;
bottom: 0;
left: 0;
background: radial-gradient(circle farthest-corner at 50% 0%, transparent 30%, #2179ea 30%, #2179ea 45%, #1d86ea 45%, #1d86ea 60%, #2a9eea 60%, #2a9eea 75%, #02b0ea 75%);
-webkit-animation: anim-h-wave 4s linear infinite, anim-v-wave 2s infinite alternate;
-moz-animation: anim-h-wave 4s linear infinite, anim-v-wave 2s infinite alternate;
animation: anim-h-wave 4s linear infinite, anim-v-wave 2s infinite alternate;
}
.container {
width: 100%;
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
#-webkit-keyframes anim-h-wave {
0% {
background-position: -100px 0;
}
100% {
background-position: 100px 0;
}
}
#keyframes anim-h-wave {
0% {
background-position: -100px 0;
}
100% {
background-position: 100px 0;
}
}
#-webkit-keyframes anim-v-wave {
0% {
background-size: 100px 220px;
}
100% {
background-size: 100px 270px;
}
}
#keyframes anim-v-wave {
0% {
background-size: 100px 220px;
}
100% {
background-size: 100px 270px;
}
}
<section id="above-the-water">
<div class="above-water">
<div class="wave"></div>
</div>
</section>
<section id="underwater">
<div class="container">
<h1>test</h1>
</div>
</section>
If needed, the full code can be found on my pen at https://codepen.io/sabey-dc/pen/zYOdNOv
You've got to add margin-top: 100vh to the underwater section because since the above water has absolute positioning, it won't push the underwater content down on its own.

How can I create a smooth gradient background Animation?

I have created a div which has a gradient background, and I want to change this gradient. I applied a keyframes animation which changed background color instantly. How can I make this change smooth?
div {
width: 100px;
height: 100px;
background:linear-gradient(red, yellow);
animation-name: colorchange;
animation-duration: 5s;
-webkit-animation-name: colorchange;
animation-iteration-count: 5;
-webkit-animation-duration: 5s;
text-align: center;
}
#keyframes colorchange {
0% {background:linear-gradient(red, yellow) }
35% {background:linear-gradient(yellow, green) }
70% {background:linear-gradient(green, red) }
100%{background:linear-gradient(red, yellow)}
}
<div>
Gradient Background
</div>
Try this
div {
text-align: center;
width: 100px;
height: 90px;
color: #fff;
background: linear-gradient(0deg, red, yellow, green);
background-size: 400% 400%;
-webkit-animation: Gradient 15s ease infinite;
-moz-animation: Gradient 15s ease infinite;
animation: Gradient 15s ease infinite;
}
#-webkit-keyframes Gradient {
0% {
background-position: 50% 0%
}
50% {
background-position: 50% 100%
}
100% {
background-position: 50% 0%
}
}
#-moz-keyframes Gradient {
0% {
background-position: 50% 0%
}
50% {
background-position: 50% 100%
}
100% {
background-position: 50% 0%
}
}
#keyframes Gradient {
0% {
background-position: 50% 0%
}
50% {
background-position: 50% 100%
}
100% {
background-position: 50% 0%
}
}
<div> Text </div>
I might be wrong, but gradients don't support transitions.
There's a workaround I found in other related question:
https://medium.com/#dave_lunny/animating-css-gradients-using-only-css-d2fd7671e759
As far as I'm concerned, the smooth transition doesn't work with gradient backgrounds, only with straight colors.
You can create a large gradient background with many colors though, and use the transition to move it. This creates the illusion of the colors changing.
body {
width: 100wh;
height: 90vh;
color: #fff;
background: linear-gradient(-45deg, #EE7752, #E73C7E, #23A6D5, #23D5AB);
background-size: 400% 400%;
-webkit-animation: Gradient 15s ease infinite;
-moz-animation: Gradient 15s ease infinite;
animation: Gradient 15s ease infinite;
}
#-webkit-keyframes Gradient {
0% {
background-position: 0% 50%
}
50% {
background-position: 100% 50%
}
100% {
background-position: 0% 50%
}
}
#-moz-keyframes Gradient {
0% {
background-position: 0% 50%
}
50% {
background-position: 100% 50%
}
100% {
background-position: 0% 50%
}
}
#keyframes Gradient {
0% {
background-position: 0% 50%
}
50% {
background-position: 100% 50%
}
100% {
background-position: 0% 50%
}
}
h1,
h6 {
font-family: 'Open Sans';
font-weight: 300;
text-align: center;
position: absolute;
top: 45%;
right: 0;
left: 0;
}
<h1>Hello World!</h1>

Animate a Sprite grid using CSS3?

I've got this sample sprite grid sheet that I need to run through and animate. I am able to reach a certain point but struggling to make it perfect. The animation is not that smooth and additionally, the image is not aligned properly. During the animation, you can see image elements not centered with other elements in the view. Here is my HTML and CSS3 code so far.
.hi {
width: 910px;
height: 340px;
background-image: url("https://simba-heroku.imgix.net/animation-homepage-tablet-retina.jpg?auto=format,compress");
position: relative;
-webkit-animation: playv 12s steps(6) infinite, playh 2s steps(4) infinite;
}
#-webkit-keyframes playv {
0% { background-position-y: 0px; }
100% { background-position-y: 100%; }
}
#-webkit-keyframes playh {
0% { background-position-x: 0px; }
100% { background-position-x: 100%; }
}
<div class="hi">
</div>
Fiddle: http://jsfiddle.net/bf5ckdv9/
I have added a background dimension style, and rearranged some of your properties
the result is almost ok; but your sprite grid seems to be out of order
.hi {
width: 910px;
height: 340px;
background-image: url("https://simba-heroku.imgix.net/animation-homepage-tablet-retina.jpg?auto=format,compress");
position: relative;
animation: playh 2s steps(5) infinite, playv 10s steps(5) infinite;
border: solid 1px blue;
background-size: 500% 500%;
background-repeat: no-repeat;
}
#keyframes playv {
0% { background-position-y: 0px; }
100% { background-position-y: 125%; }
}
#keyframes playh {
0% { background-position-x: 0%; }
100% { background-position-x: 125%; }
}
<div class="hi">
</div>

scrolling background in one direction only

All I want to have a background scrolling effect from bottom to top ,but I dont know how to do so. I have tried it using CSS ,but the problem arises here is it scroll in both direction i.e bottom to top and top to bottom.
* {
margin: 0;
padding: 0;
}
div {
width: 100vw;
height: 100vh;
animation: change 2s infinite ease-in both;
background-image: url(http://hdwallpaperbackgrounds.net/wp-content/uploads/2016/07/background-pictures-2.jpg);
background-size: cover;
background-repeat: no-repeat;
}
#keyframes change {
0%, 100% {
background-position: 0% 5%;
}
5% {
background-position: 0% 10%
}
10% {
background-position: 0% 15%
}
15% {
background-position: 0% 20%
}
20% {
background-position: 0% 25%
}
25% {
background-position: 0% 30%;
}
30% {
background-position: 0% 35%
}
35% {
background-position: 0% 40%
}
40% {
background-position: 0% 45%
}
45% {
background-position: 0% 50%
}
}
<div>
<h1> This is animating background ...</h1>
</div>
You can achieve that by just using the to and from attributes for the keyframes change. The effect is kind of weird, because the background top and bottom do not fit together...
* {
margin: 0;
padding: 0;
}
div {
width: 100vw;
height: 100vh;
animation: change 3s linear infinite;
background-image: url(http://hdwallpaperbackgrounds.net/wp-content/uploads/2016/07/background-pictures-2.jpg);
background-size: cover;
background-repeat: repeat-y;
background-position: 0 0;
}
#keyframes change {
from {
background-position: 0 100vh;
}
to {
background-position: 0 0;
}
}
<div>
<h1> This is animating background ...</h1>
</div>

CSS3 image rotator

So I'm making a preloader animation which will be a 4 divs with background images crossfading. I'm wanting them nicely crossfaded at 0.6 seconds each but I'm having no luck. They keep overlapping each other too much and it's just a mess. I feel I just need the right percentage or something.
.start_loader .iconfader {
position:absolute;
width: 200px;
height: 200px;
left:50%;
top:50%;
margin-left:-100px;
margin-top:-100px;
-webkit-animation-name: fade;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: 5s;
animation-name: fade;
animation-iteration-count: infinite;
animation-duration: 5s;
}
#load-icon1 {
background: url(http://mydomain.com/loader-01.png) no-repeat center center;
background-size: 200px 200px;
}
#load-icon2 {
-webkit-animation-delay: -3s;
background: url(http://mydomain.com/loader-02.png) no-repeat center center;
background-size: 200px 200px;
}
#load-icon3 {
-webkit-animation-delay: -2s;
background: url(http://mydomain.com/loader-03.png) no-repeat center center;
background-size: 200px 200px;
}
#load-icon4 {
-webkit-animation-delay: -1s;
background: url(http://mydomain.com/loader-03.png) no-repeat center center;
background-size: 200px 200px;
}
#-webkit-keyframes fade {
0% {opacity: 0;}
25% {opacity: 1;}
33% {opacity: 1;}
53% {opacity: 0;}
100% {opacity: 0;}
}
#keyframes fade {
0% {opacity: 0;}
20% {opacity: 1;}
33% {opacity: 1;}
53% {opacity: 0;}
100% {opacity: 0;}
}
I have done this on Codepen. Check this.
No need 4 divs for this. we can do this on single div with CSS3
http://cdpn.io/rFpmx
CODE
<div class="loader anim-1"></div>
<div class="loader anim-2"></div>
CSS
.loader {
height: 80px;
width: 80px;
position: relative;
margin: 100px auto;
}
.loader:after {
content: "";
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: absolute;
top: 0;
left: 0;
display: block;
height: 80px;
width: 80px;
}
.loader.anim-1:after {
-webkit-animation: fader 2.4s linear infinite;
}
.loader.anim-2:after {
-webkit-animation: fader2 2.4s linear infinite;
}
#-webkit-keyframes fader {
0%, 20%, 100% {
background-image: url(http://m.c.lnkd.licdn.com/mpr/mpr/shrink_80_80/p/3/000/01f/210/0fedb27.jpg);
}
25%, 45% {
background-image: url(http://m.c.lnkd.licdn.com/mpr/mpr/shrink_80_80/p/4/005/025/0d0/3ec916f.jpg);
}
50%, 70% {
background-image: url(http://m.c.lnkd.licdn.com/mpr/mpr/shrink_80_80/p/4/000/143/350/1ca561e.jpg);
}
75%, 95% {
background-image: url(http://m.c.lnkd.licdn.com/mpr/mpr/shrink_80_80/p/8/000/2cb/256/2f5ed8e.jpg);
}
}
#-webkit-keyframes fader2 {
0%, 100% {
background-image: url(http://m.c.lnkd.licdn.com/mpr/mpr/shrink_80_80/p/3/000/01f/210/0fedb27.jpg);
}
25% {
background-image: url(http://m.c.lnkd.licdn.com/mpr/mpr/shrink_80_80/p/4/005/025/0d0/3ec916f.jpg);
}
50% {
background-image: url(http://m.c.lnkd.licdn.com/mpr/mpr/shrink_80_80/p/4/000/143/350/1ca561e.jpg);
}
75% {
background-image: url(http://m.c.lnkd.licdn.com/mpr/mpr/shrink_80_80/p/8/000/2cb/256/2f5ed8e.jpg);
}
}