keyframe animations do not work when combining 'left' and 'right' in CSS

Looking for a solution to create a horizontal text-in-several-divs animation with dynamic width based on user input. I am not using jquery for this particular implementation. The animation involves multiple div elements displaying text strings, each considered as a 'unit'. Users can input any number of text strings and we append a new div to the right end of the existing ones:

<div> TEXT1 </div>, <div> TEXT2 </div>, ...., <div> TEXT-N </div>

The technique used here is keyframe animation. Here's what needs to be achieved:

1) At the start of the animation (0%), the left edge of the text/divs content should be positioned 2 pixels from the left of the page.

2) At the end of the animation (100%), the right side of the text/div content should be approximately 20 pixels from the right of the page.

An attempted solution involved defining the following CSS properties:

<style> 
.cssHorizontalAnimatedText
{
position:absolute;
animation:leftMovingTextStuff 10s infinite;
animation-timing-function: linear;
white-space: nowrap;
}

@keyframes leftMovingTextStuff
{
0% { 
left:20px;
}
100%
{
right:-20px;
}
}
</style>

<div class="cssHorizontalAnimatedText" style='width:100%;overflow-x:hidden;height:41px;'>
<?php echo $theArbitrarilyLongDivsAndText ?>
</div>

However, the issue arises when attempting to use either only 'left' or 'right' values in the keyframes. It results in a left-to-right scrolling motion of the content. Using both 'left' and 'right' together prevents any movement completely. Is there a way to combine these positions effectively within the keyframes to achieve the desired outcome?

The goal is to have the long text-and-divs content set up such that:

1) At the start of the animation (0%), the left edge of the content should be 2 pixels from the left of the page.

2) At the end of the animation (100%), the right side of the content needs to be about 20 pixels from the right of the page.

Any suggestions on how to accomplish this effectively using keyframes?

Answer №1

Regrettably, I had to ditch keyframes animation in this case and instead developed my own solution using JavaScript.

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

Surprising outcomes when hosting my website on its domain

During the development of my website, I uploaded it to Cpanel once everything was finished. It functioned perfectly fine at that time. However, after making some changes and uploading it again, the fonts and videos on the live domain appear larger than i ...

Can you explain the significance of a percentage in relation to the `word-spacing` property?

MDN states that the word-spacing property has the ability to accept a percentage value, which "specifies extra spacing as a percentage of the affected character’s advance width." However, there are some conflicting observations: The demonstration on th ...

Get rid of unnecessary markup rather than just hiding it in ASP.NET

Is it possible to completely remove unused controls from the codebehind when designing a page in ASP.NET instead of just hiding them? Hiding controls can result in whitespace on user screens. For example: <td> <uc1:GoToRequestControl id="UserCon ...

The element refuses to accept the appendChild method

I've created a tampermonkey script that generates certain elements and adds them to the page. The first element, named ControllerBG, is appended to an element with the id "motd". However, when I try to append a second element, nothing appears on the ...

What is the best way to turn a calendar table's <td> elements into interactive form elements?

I am currently working on developing an events booking form, but I am facing a challenge. I want users to be able to click on a specific date in a table cell representing a calendar to select their start date. However, my expertise lies more in PHP progra ...

The Impact of Using Custom HTML Tags with AngularJS Directives

If I were to create a unique avatarDirective in AngularJS that is connected to an userEmail property on the scope. The directive would update this HTML … <avatarDirective userEmail="user.email" /> with a standard img tag that has its src attribut ...

unable to pre-select default option

My dynamic options select is functioning correctly, adding the selected attribute to a specific option with an id value. However, I am encountering an issue where even with an option that has the selected attribute, the first option is always displayed as ...

Is it possible to display a variety of color schemes in just one console.log()?

My task involves working with an array of hexadecimal values, "colors": ["#d5dd90","#e6bb45","#ef9770"] To log these out in different colors, I used the following method: colors.forEach((value)=>{ console.log(& ...

Disappearance of CSS borders when using jQuery scroll function

After implementing a fixed table header for an HTML table on my website, I encountered a minor issue. When scrolling down, the table header remains at the top as intended, but the CSS styling for borders within each <th> element disappears. The font ...

JS failing to validate inputs

I'm facing an issue with my validation code. It doesn't seem to be working correctly. The two things I'm trying to validate are: Check if any textfield is empty Ensure that the password field has a minimum of 8 characters If either one o ...

Pictures that can be chosen in a fashion similar to checking off a box

I am just starting out in the world of web development and I have a specific idea in mind. I want to create images that act like checkboxes, where only one can be selected at a time. Here is an example of what I'm looking for: https://i.sstatic.net/Nu ...

generate a flexible div that adjusts its height based on the size of the browser window

Is it possible to create a div layout structured like this: <div_wrapper> <div_header> </div_header> <div_content> </div_content> </div_wrapper> Upon page load, the div_header o ...

I'm having trouble retrieving and rendering data in HTML using AngularJS and Spring

After fetching the data, I am unable to see it in the HTML code. The web browser console displays the JSON data but it is not visible in the HTML code. Here is my AngularJS code: $scope.refresh = function(){ fetchData(); }; $scope.fetchData = functio ...

Ways to clear the cache on a webpage after updating scripts

After scouring the internet for a way to update user cache when a website is modified, I came up empty-handed. The only suggestion I found was setting version control on the URL of the script files... Below, I'm sharing my own solution and I'm w ...

How to perfectly center a background image using CSS

I am currently working on a project that involves using a background image. However, I am facing some difficulties in trying to fully center the image, similar to what is shown in this My objective is https://i.sstatic.net/XUNTy.png What I have achieved s ...

CSS Causing Numbers to Display in the Incorrect Direction

I'm attempting to showcase numbers in a single line using CSS. It's almost perfect, except the numbers are appearing in reverse order (e.g. 4 - 3 - 2 - 1 instead of 1 - 2 - 3 - 4). I've tried utilizing "direction: ltr" without success. My C ...

Equal spacing title in horizontal menu with Bootstrap design

Is there a way to evenly distribute menu links with varying text lengths in equal width bootstrap columns? Adjusting the column class between col-md-1 and col-md-3 doesn't seem to give accurate spacing. If you want to see, I've set up a fiddle h ...

Eliminate classes from radios that are not selected

Here is a snippet of the code I am working with: <ul id="id_priori"> <li> <label for="id_priori_0"> <input id="id_priori_0" name="priori" type="radio">Hola </label> </li> </ul> ...

Tips on preserving CSS modifications made in Chrome Developer Tools Inspector to .vue file

Currently, I am in the process of setting up a new workflow where my goal is to streamline my work by using the Chrome DevTools Inspector to save any CSS changes directly to my .vue file. While the DevTools Workspaces feature can achieve this, it involves ...

What is the best way to prevent my form from saving empty values to the database?

I am currently working on a project for managing library resources using HTML5, PHP, and SQL. I have implemented form validation using PHP for fields such as email, password, name, surname, and phone number. The validation seems to work visually, but it st ...