Best way to create animation form left to right with css - html

I wan to make animation from left to right (animation start in invisible area like left: -100px) and end in invisible area too (right: -100px) I am using this code which works but not correctly on different sizes of screens becuase is in %. And i need to remake it but i dont know how.
.ip_first_block {
width: 100%;
height: 100%;
}
section {
position: relative;
overflow: hidden;
}
.ip_welcome_text {
width: 100%;
height: 70%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.astronaut1 {
position: relative;
animation: lefttoright 10s;
animation-fill-mode: forwards;
}
#keyframes lefttoright {
from {
transform: translateX(-1500%);
}
to {
transform: translateX(2200%);
}
}
<section style="height:100%;">
<div class="ip_first_block" id="ifb">
<div class="ip_welcome_text">
<div class="astronaut1">
<img src="images/astronaut.svg" height="70px" ; width="70px;" />
</div>
</div>
</div>
</section>

It's easier if you animate the position, e.g. left property:
body {margin: 0}
.astronaut1 {
overflow: hidden;
}
img {
position: relative;
left: -70px; /* starting point; needs to be at least the img width to hide it */
animation: lefttoright 10s forwards;
}
#keyframes lefttoright {
to {left: 100%} /* cover the entire parent width */
}
<div class="astronaut1">
<img src="http://placehold.it/70x70" alt="" height="70" width="70">
</div>

Related

Smooth animation loop for horizontal text scroll

I'm trying to have an infinite keyframe animation for text (span) moving horizontally by using the translateX property.
I manage to have the beginning of the infinite animation, however when I reach the end of the animation it "jumps" back to the beginning without it being smooth.
Also when reaching the last span of the animation, I would like that we start to see the beginning of the first span, so that it looks like it's indefinitely scrolling and not have blank space at the end of the animation.
I also tried to create different keyframes for each span, but this method made it very difficult to time the speed.
html, body {
margin: 0;
}
.scroll {
display: flex;
position: relative;
width: 100%;
height: 15%;
min-height: 150px;
margin: auto;
background-color: #252525;
overflow: hidden;
z-index: 1;
}
.m-scroll {
display: flex;
position: absolute;
top: 0;
left: 0;
align-items: center;
justify-content: flex-start;
width: 100%;
height: 100%;
white-space: nowrap;
transform: scale(2);
transition: all 1s ease;
}
.m-scroll > div {
display: flex;
animation: scrollText 10s infinite linear;
}
.m-scroll h1 {
margin: 0;
margin-right: 150px;
font-size: 25px;
color: #ffffff;
transition: all 2s ease;
}
#keyframes scrollText {
from {
transform: translateX(0%);
}
to {
transform: translateX(-50%);
}
}
<div class="scroll">
<div class="m-scroll">
<div>
<h1>
<span>TEXT </span><span>INFINITE </span><span>SCROLL</span>
</h1>
<h1>
<span>TEXT </span><span>INFINITE </span><span>SCROLL</span>
</h1>
<h1>
<span>TEXT </span><span>INFINITE </span><span>SCROLL</span>
</h1>
<h1>
<span>TEXT </span><span>INFINITE </span><span>SCROLL</span>
</h1>
</div>
</div>
</div>
So how could I make it become smooth ?
This behavior happens in full screen, on small device, the problem doesn't seem to appear. If you run the code snippet, please expand it
I have stripped things down to give a basic continuous scroll - with the overall width of the 'sentence' (span) being a minimum 100vw in this snippet.
html,
body {
margin: 0;
}
.scroll {
position: relative;
width: 100vw;
height: 15%;
min-height: 150px;
background-color: #252525;
overflow: hidden;
z-index: 1;
margin: 0;
padding: 0;
}
.m-scroll {
overflow_ hidden;
height: 100%;
white-space: nowrap;
animation: scrollText 10s infinite linear;
margin: 0;
font-size: 0;
display: inline-block;
}
span {
font-size: 50px;
display: inline-block;
min-width: 100vw;
margin: 0;
padding: 0;
color: white;
}
#keyframes scrollText {
from {
transform: translateX(0%);
}
to {
transform: translateX(-50%);
}
}
<div class="scroll">
<div class="m-scroll"><span style="rbackground: cyan;">TEXT INFINITE SCROLL </span><span style="rbackground: magenta;">TEXT INFINITE SCROLL </span><span style="rbackground: yellow;">TEXT INFINITE SCROLL </span><span style="rbackground: gray;">TEXT INFINITE SCROLL </span></div>
</div>
Note: I removed the flexes as I have never been able to make them play nicely with scrolling text. Maybe someone can put me right on that.

Sequential text in CSS animations

I'm trying to create a sequential text animation. One line, then the next, then the next. But it animates all three lines at the same time.
.autotype {
overflow: hidden;
white-space: nowrap;
}
.autotype {
animation: autotype 8s steps(10, end);
animation-iteration-count: infinite;
}
#keyframes autotype {
from {
width: 0px;
}
}
#keyframes autotype {
0% {
width: 0px;
}
20% {
width: 70px;
}
40% {
width: 140px;
}
60% {
wdith: 210px;
}
80%. {
width: 280px;
}
100% {
width: 500px;
}
}
.alignnone {
height: 20px;
width: 50px;
position: relative;
top: 4px;
}
<div class="autotype">.
<p>Hello, and welcome to
<img src="http://4309.co.uk/wp-
content/uploads/2020/01/
Screenshot_20200110_150836-
300x115.jpg" alt="" width="300" height="115" class="alignnone size-medium
wp-image-8431" />Feel free to look</p>
<p>around the site and contact us via the form<br> on the contact page</div>
So how do i animate it so that it reveals the first line, and only when this is fully revealed begins the second and so on. I've tried using height in the animation itself but, whilst this works for the first line, when it goes higher for the next line they've already rendered.
Since CSS cannot detect characters, I suggest you to
Wrap the lines inside a separate class autotype1, autotype2 and autotype3.
Hide the other lines initially with width: 0 or opacity: 0;
Use animation-delay with timing like 2n, 3n to make it sequential.
If you want to make it infinite, you might want to add a bit of JS with the help of these answers: CSS animation delay in repeating
.autotype {
overflow: hidden;
white-space: nowrap;
}
.autotype {
animation: autotype 4s steps(10, end);
animation-fill-mode: forwards;
}
.autotype2 {
width: 0;
animation-delay: 4s;
margin-bottom: 0;
}
.autotype3 {
width: 0;
animation-delay: 8s;
margin-top: 0;
}
#keyframes autotype {
from {
width: 0px;
}
}
#keyframes autotype {
0% {
width: 0px;
}
20% {
width: 70px;
}
40% {
width: 140px;
}
60% {
width: 210px;
}
80%. {
width: 280px;
}
100% {
width: 500px;
}
}
.alignnone {
height: 20px;
width: 50px;
position: relative;
top: 4px;
}
<div>.
<p class="autotype autotype1">Hello, and welcome to
<img src="http://4309.co.uk/wp-
content/uploads/2020/01/
Screenshot_20200110_150836-
300x115.jpg" alt="" width="300" height="115" class="alignnone size-medium
wp-image-8431" />Feel free to look</p>
<p class="autotype autotype2">around the site and contact us via the form<br>
</p>
<p class="autotype autotype3"> on the contact page</p>
</div>

large image not shrinking to css grid container on browser resize

I have a simple grid layout with a main area on top and a nav area on bottom. I am just starting using css grid and am having trouble with having a responsive image that stays in the grid container. It is not shrinking responsively when the browser resizes, and is extending past the border of its container. I have tried min-height/min-width: 0, object-fit: contain, changing sizes from vh/vw to 100%, changing max-widths/heights to different px and % sizes, and I still can't figure out how to make this responsive using grid. I searched pretty extensively, but nothing seems to have helped. I'm sure it's something simple that I missed, but I'm at a loss right now.
I also want to use just HTML and CSS if possible without any libraries like Bootstrap.
I put some outlines on different elements to make it easier to see what's happening that don't seem to be showing in the snippet, so if it's easier to inspect the code here is a link to the site:
https://mountainflow.design/portfolio.html
/* Box Sizing */
html {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
*,
*::before,
*::after {
-webkit-box-sizing: inherit;
-moz-box-sizing: inherit;
box-sizing: inherit;
}
/* body 100% with no margin or padding */
html {
height: 100vh;
}
body {
min-height: 100vh;
}
html,
body {
margin: 0;
padding: 0;
}
/* =================== Start Style Sheet ==========================
================================================================ */
body {
background-color: #000000;
color: #ffffff;
}
a {
color: inherit;
text-decoration: none;
}
/* Main Section */
.folio-main-container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 80% 1fr;
height: 100vh;
width: 100vw;
}
.folio-main {
outline: blue solid thin;
grid-column: 1 / 3;
grid-row: 1 / 2;
display: flex;
justify-content: center;
align-items: center;
min-height: 0;
min-width: 0;
}
.gallery-container {
outline: pink solid thin;
max-width: 970px;
min-height: 0;
min-width: 0;
position: relative;
}
/* .slideshow {
display: none;
} */
.slideshow img.responsive {
max-width: 970px;
height: auto;
}
/* .caption {
} */
/* Nav Section */
.folio-nav {
outline: red solid thin;
grid-column: 1 / 2;
grid-row: 2 / 3;
align-self: end;
justify-self: end;
padding: 2em;
}
.folio-nav ul {
display: flex;
flex-direction: row;
list-style-type: none;
}
.folio-nav li {
background: -webkit-linear-gradient(#eeeeee, rgb(158, 104, 246));
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
li {
margin-left: 2em;
}
/* Button animations */
.folio-nav li:nth-child(1) {
position: relative;
left: -1000px;
animation: navFadeIn 3s ease-in 2s forwards;
}
.folio-nav li:nth-child(2) {
position: relative;
left: -1000px;
animation: navFadeIn 3s ease-in 1.85s forwards;
}
.folio-nav li:nth-child(3) {
position: relative;
left: -1000px;
animation: navFadeIn 3s ease-in 1.7s forwards;
}
.folio-nav li:nth-child(4) {
position: relative;
left: -1000px;
animation: navFadeIn 3s ease-in 1.55s forwards;
}
.folio-nav li:nth-child(5) {
position: relative;
left: -1000px;
animation: navFadeIn 3s ease-in 1.4s forwards;
}
#keyframes navFadeIn {
0% {
opacity: 0;
}
85% {
left:0;
}
89% {
left: -5px;;
}
93% {
left: 0;
}
97% {
left: -3px;
}
100% {
left:0;
opacity: 1;
}
}
<body>
<div class="folio-main-container">
<div class="folio-main">
<div class="gallery-container">
<div class="slideshow">
<a target="_blank" href="https://sheltered-meadow-24497.herokuapp.com/" title="Fur Butlr">
<img class="responsive" src="https://github.com/mountainflow/portfolio_03/blob/master/assets/images/furButlr_970x600.png?raw=true" alt="Fur Butlr" />
</a>
<div class="caption">Fur Butlr</div>
</div>
</div>
<!-- <div class="gallery-container">
<a target="_blank" href="https://chat-meme-3fbf6.firebaseapp.com/" title="ChatMeme">
<img src="./assets/images/chatMeme_970x600.png" alt="ChatMeme" />
</a>
</div>
<div class="gallery-container">
<a target="_blank" href="https://mighty-everglades-33601.herokuapp.com/" title="Friend Finder">
<img src="./assets/images/friendFinder_970x600.png" alt="Friend Finder" />
</a>
</div>
<div class="gallery-container">
<a target="_blank" href="./assets/images/liri.gif" title="Liri">
<img src="./assets/images/liri_970x600.png" alt="Liri" />
</a>
</div> -->
</div>
<div class="folio-nav">
<ul>
<li>Home</li>
<li>Resume</li>
<li>About</li>
<li>Github</li>
<li>LinkedIn</li>
</ul>
</div>
</div>
</body>
Once I get the grid responsiveness worked out this will be a slideshow.
Thanks in advance
max-width: 100% will work for what you need.

Centring an image in a viewport regardless of viewport width

I have an image slideshow that I am trying to centre in the viewport, regardless of the viewport's width. This is easily achieved if the viewport is wider than the image by using margin: auto;, however, when the viewport is narrower than the image, like on a tablet in portrait mode, the image butts up against the left margin and does not centre.
Centred in landscape mode:
Centred in portrait mode:
This is the HTML:
<div id="slidebound">
<div class="slider">
<img src="images/slider/slide04.png" alt=""/>
<img src="images/slider/slide03.png" alt=""/>
<img src="images/slider/slide02.png" alt=""/>
<img src="images/slider/slide01.png" alt=""/>
</div>
</div>
This is the CSS:
#slidebound {
width: 100%;
height: 300px;
overflow: hidden;
}
.slider {
width: 1024px;
height: 300px;
overflow: hidden;
position: relative;
margin: 0 auto;
}
.slider img {
position: absolute;
animation: slider 32s infinite;
opacity: 0;
width: 100%;
height: auto;
}
#keyframes slider {25% {opacity: 1;} 40% {opacity: 0;}}
.slider img:nth-child(4) {animation-delay: 0s;}
.slider img:nth-child(3) {animation-delay: 8s;}
.slider img:nth-child(2) {animation-delay: 16s;}
.slider img:nth-child(1) {animation-delay: 24s;}
As per i understand, you want your image to appear in center, no-matter what the screen size is. For this you can try below code:
#slidebound {
width: 100%;
height: 300px;
overflow: hidden;
display: flex;
justify-content: center;
}
.slider {
width: 1024px;
height: 300px;
overflow: hidden;
position: relative;
margin: 0 auto;
}
.slider img {
position: absolute;
animation: slider 32s infinite;
opacity: 0;
width: 100%;
height: auto;
}
#keyframes slider {25% {opacity: 1;} 40% {opacity: 0;}}
.slider img:nth-child(4) {animation-delay: 0s;}
.slider img:nth-child(3) {animation-delay: 2s;}
.slider img:nth-child(2) {animation-delay: 3s;}
.slider img:nth-child(1) {animation-delay: 4s;}
<div id="slidebound">
<div class="slider">
<img src="http://abload.de/img/a6aawu.jpg" alt=""/>
<img src="https://nxworld.net/example/css-image-hover-effects/pic01.jpg" alt=""/>
<img src="http://abload.de/img/a6aawu.jpg" alt=""/>
<img src="https://nxworld.net/example/css-image-hover-effects/pic01.jpg" alt=""/>
</div>
You can use flexbox. But as a alternative, as you know the height and width you can use position and negative margins:
position:absolute;
left:50%;
margin-left:-512px;
top:50%;
margin-top:-150px;
See it in action.
Are you ok in using flex for your case? It depends on what browsers you need to support. You can check it out using caniuse.
In the meantime, here is a sample
https://codepen.io/hellouniverse/pen/QxwNWv
where I have centred one image both vertically and horizontally to show the way
#slidebound {
height: 100vh;
}
.slider {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
margin: 0 auto;
height: inherit;
}
<div id="slidebound">
<div class="slider">
<img src="https://naomisimson.com/wp-content/uploads/image-placeholder.jpg" alt="" />
</div>
</div>

How to make a div fit the width of its contents without causing them to wrap, while being wider than is parent

See the code in this jsfiddle: https://jsfiddle.net/frpL3yr1/
The idea is that I want a bar of images at the top of the screen. The img-wrapper div will later be animated via javascipt to move to the left when you mouse over. For an example of what I am ultimately attempting to accomplish, see this page. The difference is that in mine, the animation will only run when moused-over.
The issue is that in my jsfiddle and the linked example, the width of the div containing the images is hard-coded. In my case, the css hard-codes the width of img-wrapper to 200%. I need my page to support an arbitrary number of images, so I need its width to be equal to that of the contents. The way my jsfiddle is implemented, if there are more images that can fit in img-wrapper, they will wrap to a new line.
What is the best way to go about fixing this?
Approach using flexbox and animation:
html, body {
margin:0;
padding:0;
overflow: hidden;
}
.demo-ribbon {
width: 100%;
height: 70vmin;
margin-top: 2rem;
overflow: hidden;
}
.img-wrapper {
height: 70vmin;
width: 100%;
display: flex;
flex-flow: row nowrap;
justify-content: stretch;
}
img {
flex: 1;
object-fit: content;
margin: 0 .2rem;
width: 100vmin;
height: 100%;
}
.lead {
animation: bannermove 12s linear 320ms infinite paused alternate;
}
.img-wrapper:hover .lead {
animation-play-state: running;
}
#keyframes "bannermove" {
0% {
margin-left: 0%;
}
100% {
margin-left: -230%;
}
}
You will need to add prefixes in order to work in all browsers especially animation
Further reading: https://devdocs.io/css/animation
working pen: https://codepen.io/manAbl/pen/KROvjx ;
Aspect Ratio: https://www.w3schools.com/howto/howto_css_aspect_ratio.asp & https://css-tricks.com/aspect-ratio-boxes/
Hope helps! :)
Use flexbox and animation with translate :)
.demo-ribbon {
width: 100%;
overflow: hidden;
}
.demo-ribbon .img-wrapper {
display: flex;
justify-content: stretch;
margin-right: 0;
position: relative;
width: 100%;
}
.demo-ribbon .img-wrapper img {
transition: all 0.5s ease;
margin: 2px;
}
.demo-ribbon .img-wrapper img:first-child {
animation: lefttoRight 25s linear 320ms infinite paused alternate;
}
.demo-ribbon .img-wrapper img:hover {
transform: scale(1.1);
cursor: pointer;
box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.2);
}
.demo-ribbon .img-wrapper:hover img {
animation-play-state: running;
}
#keyframes lefttoRight {
0% {
margin-left: 0;
}
50% {
margin-left: -200%;
}
100% {
margin-left: 0%;
}
}
<html>
<body>
<div class="demo-ribbon">
<div class="img-wrapper">
<img class="lead" src="https://media-cdn.tripadvisor.com/media/photo-s/0e/9a/e3/1d/freedom-tower.jpg">
<img src="http://static.asiawebdirect.com/m/phuket/portals/www-singapore-com/homepage/pagePropertiesImage/singapore.jpg.jpg">
<img class="" src="https://www.s-ge.com/sites/default/files/cserver/styles/sge_header_lg/streamy/company/images/Hongkong-Fotolia-48687313-rabbit75-fot-282451.jpg?itok=ANpJxrgW">
<img class="" src="https://media-cdn.tripadvisor.com/media/photo-s/0e/9a/e3/1d/freedom-tower.jpg">
<img src="http://static.asiawebdirect.com/m/phuket/portals/www-singapore-com/homepage/pagePropertiesImage/singapore.jpg.jpg">
<img class="" src="https://www.s-ge.com/sites/default/files/cserver/styles/sge_header_lg/streamy/company/images/Hongkong-Fotolia-48687313-rabbit75-fot-282451.jpg?itok=ANpJxrgW">
<img class="" src="https://media-cdn.tripadvisor.com/media/photo-s/0e/9a/e3/1d/freedom-tower.jpg">
<img src="http://static.asiawebdirect.com/m/phuket/portals/www-singapore-com/homepage/pagePropertiesImage/singapore.jpg.jpg">
<img class="" src="https://www.s-ge.com/sites/default/files/cserver/styles/sge_header_lg/streamy/company/images/Hongkong-Fotolia-48687313-rabbit75-fot-282451.jpg?itok=ANpJxrgW">
<img class="" src="https://media-cdn.tripadvisor.com/media/photo-s/0e/9a/e3/1d/freedom-tower.jpg">
</div>
</div>
</body>
</html>