Eliminate the initial padding in an everlasting horizontal CSS animation

Is there a way to start an infinite horizontal animation inside the screen instead of outside and then bring it in? I have successfully implemented the animation, but it currently starts off-screen.

.marquee {
    margin: 0 auto;
    white-space: nowrap;
    overflow: hidden;
    position: absolute;
}

.marquee span {
    display: inline-block;
    padding-left: 100%;
    animation: marquee 5s linear infinite;
}

.marquee2 span {
    animation-delay: 2.5s;
}

@keyframes marquee {
    0% {
        transform: translate(0, 0);
    }
    100% {
        transform: translate(-100%, 0);
    }
}
<h1 class="marquee">
<span>Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test</span>
</h1>

<h1 class="marquee marquee2">
<span>&nbsp;Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test</span>
</h1>

Answer №1

Implement a negative delay to start the animation in the center:

.marquee {
  margin: 0 auto;
  white-space: nowrap;
  overflow: hidden;
  position: absolute;
}

.marquee span {
  display: inline-block;
  padding-left: 100%;
  animation: marquee 5s -2.5s linear infinite;
}

.marquee2 span {
  animation-delay: 0s;
}

@keyframes marquee {
  0% {
    transform: translate(0, 0);
  }
  100% {
    transform: translate(-100%, 0);
  }
}
<h1 class="marquee">
  <span>Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test</span>
</h1>

<h1 class="marquee marquee2">
  <span>&nbsp;Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test</span>
</h1>

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

Looking for a way to make text wrap neatly inside a div?

I am working on a piece of code that includes 3 images with captions below them. I want to ensure that the width of the text does not exceed the width of the image, even though the image widths can vary. If the text extends beyond the image width, it shoul ...

What could be causing my Squarespace animation to function properly in Chrome but not in Safari?

I successfully implemented a typewriter animation on my Squarespace website using a Code Block and HTML code. It seems to be functioning well on Google Chrome but is not working on Safari. I recall reading that 'transform' may require additional ...

Rowing and Columning with Bootstrap

Hey there! I'm currently working on creating some stylish boxes to showcase text and possibly an image background. However, I'm encountering an issue where the boxes are not aligning correctly on smaller screens. https://i.sstatic.net/JoYtj.jpg ...

Show the output of JQuery in the text input area

Can anyone help me figure out how to display the value of #response in an input field instead of a div? I've tried using the code below, but it didn't work: <div id="response"></div> I attempted to use an input field like this, ...

Is it possible to update table cell content depending on selected option?

Displayed here is the select block: <form> <select id="select"> <option disabled selected value="choose"> CHOOSE </option> <option value="i2g" id="i ...

Having the ability for two images to adjust in size, becoming smaller or larger, as the page is resized and displayed

On my webpage, I have two divs positioned side by side with images inside them. Everything looks perfect when viewed on my Macbook 13 inch screen, but as I resize the browser window, the photos start to spread apart and create a large gap between them. Is ...

Can you provide me with ideas on how to create a unique border design for a div box? Thank you!

The challenge lies in the fact that the dimensions and position of the div box will be dynamically changing through JavaScript, while also requiring the box to remain completely transparent. Refer to the image for a visual understanding of what I'm t ...

An issue arises when attempting to capture a screenshot with three.js, displaying the error message: "'modelViewMatrix' is a data that cannot be modified or configured."

Currently, I am utilizing three.js within my Vue application with the goal of capturing a screenshot of my scene as a blob. Initially, I tested this functionality by implementing: window.addEventListener('keydown', this.test.bind(this)); Within ...

The use of jQuery addClass does not produce any changes

I am trying to modify a single attribute in my class using a JavaScript function. .msg_archivedropdown:before { content:""; display: block; position:absolute; width:0; height:0; left:-7px; top:0px; border-top: 10px solid tr ...

What steps should I follow to produce animation in my specific situation?

I've been attempting to implement a transition for my elements, but the examples I've come across all rely on the :hover state. What I really need is for the transition to activate when I click a link. Here's my HTML: html <a id=' ...

The azure streak on the mobile dropdown menu

After successfully publishing my website using quarto with R, everything appears fine on desktop and mobile except for a minor issue with drop down menus on iPhone, showing blue lines when clicked. https://i.sstatic.net/xJRmU.jpg At the bottom of my .yml ...

Utilize a unique CSS selector and content property to insert a space character between two inline-block elements

I have a group of connected span elements with the class tag from bootstrap v4. Because they are generated from a react.js array of JSX elements, they sit adjacent to each other without any spacing between them: <span class="tag tag-primary">text< ...

Extracting names from HTML can be done easily by looking for the "@" symbol that the

My HTML structure looks like this: <table id="table-15244" cellspacing="0" class="comment"><tbody> <tr id="comment-37"> <td style="color: #999" class="NV"> </td> <td class="hidden-mob"> ...

An issue with Destination-Out Composition in HTML5 Canvas

While working on a canvas, I have encountered an issue with deleting a portion of a curve I have drawn. Specifically, I need to remove the last 25% of the curve after it is complete and keep only the first 75%. However, when attempting to delete the lines ...

Tips for confirming that the text in a particular element is visible on the page when utilizing Selenium IDE

I'm stuck on a question that I can't figure out. Could someone help me locate the current element displayed below: <td style="width: 250; text-align:right" class="stData"> March 14 2014, 00:00 </td> that specifically includes the t ...

When a cursor hovers over an image, a dark line appears

I wanted to create a hover effect where the image would enlarge when hovered over. I achieved this using a JavaScript function that applies the transform property with a scale of 1.2 to the picture. However, during the animation, a black line appears at th ...

How to align Font Awesome icons inside `<span>` vertically with each other

Trying to vertically align multiple font awesome icons: ############################# icon icon icon icon icon icon ############################# <div class="announcement-card-body modal-body card border-0"> <span class="info fa fa-info- ...

Ascending to the Peak within a div

<script type="text/javascript"> $(document).ready(function(){ updateContent(); }); function updateContent(){ $('#mainDiv').load('home.php', function(){ scrollToTop(); }); } ...

Utilizing the append method to extract information from a multidimensional array

I'm currently facing an issue with my code structure. Here is the existing code snippet: .append("Last Name {}, First Name {} Stats: {}".format(result["L_Name"], result["F_Name"], result["Stats"])) The output generated by this code is not exactly wh ...

Having difficulty extracting information from an HTML page using Swift

I'm attempting to convert data retrieved from an HTML page into a readable format, but the string urlContent is showing as nil even though the data received from the NSURLSession is not null. This is my approach: var city = "London" var url = NSURL ...