Struggling to get CSS animation to function properly

I'm having some trouble with this code and could use some help figuring out what's wrong. I tried using -webkit- but it didn't work when trying to animate the objects across the screen.

Here is the HTML:

<body>

    <h1 class='cloud'>
    SKILLS
    </h1>

    <h1 class='balloon'>
    WORKS
    </h1>

</body>

And here is the CSS:


   .cloud  {
       background: url(../image/cloudskills.svg) no-repeat;
       height: 100px;
       width: 130px;
       text-indent: -999em;
       animation: cloud 5s linear infinite;
       -webkit-animation: cloud 5s linear infinite;
    }

    @-webkit-keyframes cloud {
       0%, 100% {
         left: 0%;
       }
       50% {
         left: 100%;
       }
    }

   .balloon {
     background: url(../image/balloonworks.svg) no-repeat;
     width: 100px;
     height: 130px;
     text-indent: -999em;
     animation: balloon 5s linear infinite;
   }

   @keyframes balloon{
     0%, 100% {
      left: 0%;
     }
     50% {
      left: 100%;
     }
   }

Answer №1

Check out this Js Fiddle for an example

To create animations for elements, you need to specify the position property as either absolute or relative. Alternatively, you can use margin within keyframes to manipulate the movement of the element.

.cloud {
    background: url(http://cdn.flaticon.com/png/256/8800.png)no-repeat;
    height:100px;
    width:130px;
    background-size:100px auto;
    text-indent: -999em;
    animation: cloud 5s linear infinite;
    -webkit-animation: cloud 5s linear infinite;
    position:relative;
}
@-webkit-keyframes cloud {
    0%, 100% {
        left: 0%;
    }
    50% {
        left: 100%;
    }
}
.balloon {
    background: url(http://cdn.flaticon.com/png/256/8800.png)no-repeat;
    background-size:100px auto;
    width: 100px;
    height: 130px;
    text-indent: -999em;
    animation: cloud 5s linear infinite;
    -webkit-animation: cloud 5s linear infinite;
    position:relative;
}
@-webkit-keyframes balloon {
    0%, 100% {
        left: 0%;
    }
    50% {
        left: 100%;
    }
}

Answer №2

I made a slight modification to your code snippet http://jsfiddle.net/2gbngtxp/

@-webkit-keyframes cloud {
   0% {
   left: 0;
 }
   50% {
   margin-left: 100%; /*changed 'left:100%' to 'margin-left:100%'*/
 }
100%{
    left:0;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Shift the image down to the bottom of the sidebar

This is the code for my sidebar HTML, with the side navigation bar positioned on the left: #main-container { display: table; width: 100%; height: 100%; } #sidebar { display: table-cell; width: ...

"How can I adjust the positioning of a Materialize modal to be at the top

I am encountering an issue where the modal is being displayed automatically without any trigger when I try to set the top property in the #singlePost. Despite attempting $('#singlePost').css("top", "1%");, it does not seem to work. I have also ex ...

Determine the dimensions of an iframe containing script tags

I am trying to determine the size of an iframe content that contains <script> tags. These <script>s generate additional content dynamically. You can view a codepen example here: https://codepen.io/ygygy/pen/YzQpdoV?editors=1010. (Feel free to ...

Refine your search by name following the implementation of a character-altering filter

Encountered a scenario in which there is a need to filter elements generated by the 'ng-repeat' directive. I have implemented a custom filter that replaces one character with another and vice versa for each element created. However, when attempt ...

How to manage the onClick event in HTML while the page is still loading?

When I try to call the Javascript function from the HTML onClick event, everything works smoothly if the page is already loaded. However, if I click the button before the document is ready, I encounter an undefined function error in the console. <a oncl ...

Constructing Jquery object with added event listener

Take a look at the code I've provided below: <body> <canvas id="canvas" height="300" width="300" style="border:1px solid" /> </body> <script> function maze(canvas){ this.ctx = canvas[0].getContext("2d"); ...

Combining dropdowns, nav-pills, and separate links in Bootstrap 4 to create a seamless horizontal layout

Trying to achieve a layout in Firefox where everything is displayed in one single horizontal row. This includes the label Dropdown, dropdown box itself, bootstrap nav-pills menu, and separate link. Code snippet: (jsfiddle: https://jsfiddle.net/aq9Laaew/16 ...

Why is it that when I use XMLHttpRequest for a menu and request a page with HTML that contains JavaScript, nothing happens?

Below is the code snippet I'm using for a menu in a webpage I am currently developing. In some cases, the page I want to request contains JavaScript, but when the requested page is loaded into the actual page, the script does not run. //Ajax menu all ...

Generating a variety of distinct HTML elements in a PHP foreach loop

In the process of building a website, I am faced with the task of retrieving multiple rows of data from my database. Each displayed row should be accompanied by a button with a unique name. However, I am struggling to ensure that each button is assigned a ...

What is causing the issue in retrieving the JSON response from Django using the JavaScript Fetch API?

I am inexperienced with JavaScript. Currently, I am working on a project that involves using Django in the backend. In this project, my Django views function will generate a JSON response that my JavaScript fetch will retrieve. Below is the Django views fu ...

Align an Image Vertically Using Bootstrap's Grid System

Hey there! I've been trying to center an image within a "div" tag using Bootstrap, but despite my best efforts and reading through various resources, I haven't been able to crack it. * { margin: 0; padding: 0; } .people-one { w ...

Troubleshooting image resolution issues in ASP web application (using C#)

I've been working on developing an asp web application that requires users to register details of a person, including uploading an image. The file name of the details/image are stored in a SQL database with the image filename saved in an NVARCHAR colu ...

When the icon is clicked, the text goes over the ul and the mobile slide menu goes beneath it

click here for the image Is there a way to make the text move below when I click on the hamburger menu icon? ...

The conflict between CSS link types and image links causing disruption

I am currently designing my own Tumblr theme and have encountered an issue that I cannot resolve due to lack of expertise. I was hoping someone with more knowledge could assist me. Essentially, I have implemented a feature where hovering over a link chang ...

Tips on enhancing the appearance of your numberbox with vibrant colors

Hello everyone! I am working with some devextreme code blocks and need help in changing the border color of a numberbox to red. Can anyone guide me on how to achieve this? import React, { useState } from 'react'; import { NumberBox } from 'd ...

"Implementing responsive design with Bootstrap's carousel through media queries

I'm having some trouble creating a basic carousel using bootstrap because the images are not displaying full screen. Do I need to use media queries to achieve this and if so, how can I implement them? <div id="myCarousel" class="carousel slide" da ...

Is there a way to transform JSON into HTML with PHP?

I am attempting to reverse engineer the function referenced in this discussion: [Post][1] [1]: https://stackoverflow.com/a/23427469/19867306 @scozy demonstrated a function for converting HTML text to a JSON model. Now, I need to convert the same JSON mode ...

creating divisions between tables using css and html

Just starting out in web development and coding, I have a query about separating two tables. How can I do this? The relevant code is a few lines down. <table border="1" width="35%" cellspacing="10" cellpadding="5"> <tr> <th colspan= ...

Utilize itextsharp to transform HTML into PDF files

When I try to convert HTML to PDF using iTextSharp, the CSS styling I apply to the webpage does not get carried over to the converted PDF file. Here is the CSS code I am using: <style type="text/css"> .cssformat { ...

What is the best way to transfer information from a parsed CSV file into select dropdown boxes?

I utilized JavaScript to parse the CSV file. Here is an example of a CSV: Year,Model,Mileage,Color,Vin,Image 2012,BUICK LACROSSE FWD V6 FFV 4D SEDAN LEATHER,113046,BROWN,1G4GC5E34CF177752,https:imagelink Below is the code used for parsing: $(document). ...