Problems with CSS text scrolling

We have a client who wants a marquee-style scrolling text banner, and I tried using CSS animations to achieve it. However, I encountered some quirks that I'm struggling to fix.

If you want to take a look at the issue, here is the link: https://jsfiddle.net/u2f6qdya/

The problem I'm facing is that the list elements get pushed out of line and stack up until the last one. The parent element is positioned absolutely, so I'm not sure why this is happening.

Another issue is with the keyframes. I want the items to start on the far left side of the screen, but they start coming in and scrolling before they have finished animating off the right side of the screen.

Here is the CSS code:

.sliding-marquee {
    width: 100%;
    height: 44px;
    background-color: #000;
    opacity: 0.6;
    color: white;
    line-height: 44px;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    margin-top: 10px;
}

.sliding-marquee ul {
    left: 0;
    top: 0;
    position: absolute;
    animation: marquee 20s linear infinite;
}

.sliding-marquee ul li {
    display: inline-block;
    font-size: 20px;
    text-transform: uppercase;
}

.sliding-marquee ul li i {
    margin-right: 20px;
}

.sliding-marquee ul li + li {
    margin-left: 40px;
}

@keyframes marquee {
    0%   { left: -100% }
    100% { left: 100% }
}

And here is the markup:

<div class="sliding-marquee">
    <ul>
        <li>TEXT 1</li>
        <li>LONGER TEXT 2</li>
        <li>EVEN LONGER TEXT 3</li>
    </ul>
</div>

Answer №1

Check out this CSS solution I found that might be helpful.

https://jsfiddle.net/72g81d9c/

I came up with the concept by examining text width using the Chrome Element Inspector tool.

@keyframes scrolling {
    0% {
        left: -500px;
    }
    100% {
        left: 100%;
    }
}

Answer №2

One problem that needs to be addressed is the necessity of including position: absolute; along with a width: 100%; or similar property for the .sliding-marquee ul element. Failure to set the width to 100% will result in the default behavior of right: 0;, causing the width to transition from 100% to 0% during the animation.

To resolve this issue, check out the modified version here: https://jsfiddle.net/wtm_w/0hp144r0/

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

Internet Explorer 9 does not display content until the ajax/json function has finished executing

I have encountered an issue with my code regarding updating a div element. The first innerHTML call seems to be ineffective and does not render in the browser. However, the second innerHTML call works as expected by appending "Complete" once the ajax call ...

Prioritizing nth child over the first child

I have a situation where I need to maintain 3 different styles in a patterned design without altering the classes on the HTML side. I have been attempting to achieve this using nth-child selectors. However, I am facing an issue where my first class is bein ...

Leveraging personalized data-* attributes within the <template> tag in HTML5

I am currently developing a menu using a dom-repeat template as shown below: <template is="dom-repeat" items="{{appletsMenu}}"> <a data-route="{{item.dataRoute}}" href="{{item.href}}"> <iron-icon icon=" ...

Developing a timetable feature using PHP

I am working on creating a schedule page that involves an SQL table named 'appointments' with columns for id, name, date, and time. My goal is to organize the data from this table into an HTML/CSS based table where all records with the same date ...

Having difficulty automating the selection of dropdown menu using Selenium in Python

I'm struggling to automate the selection of a specific element on this webpage using Selenium in Python. The elements I'm targeting from the webpage are as follows: Upon inspecting the page element, I found this portion of the HTML markup: < ...

Struggling with implementing the use of XMLHttpRequest to transfer a blob data from MySQL to JavaScript

I have a blob stored in my local WAMP64/MySQL server that I need to retrieve and pass to an HTML file using XMLHttpRequest. I know I should set responseType="blob", but I'm not sure how to transfer the blob from PHP to JavaScript in my HTML file. Any ...

Is it possible to use CSS to target the nth-child while also excluding certain elements with

How can I create a clear break after visible div elements using pure CSS? Since there isn't a :visible selector in CSS, I attempted to assign a hidden class to the div elements that should be hidden. .box.hidden { background: red; } .box:not(.hid ...

Aligning the .left position to make the border of a <div> synchronized

When working on my Jquery program, I encountered an issue with borders not aligning properly within the container. Specifically, in the execution (where the container is represented by a white box), the left border extends beyond the position().left proper ...

Fraudulent emails targeting my posted ads - beware!

Operating a classifieds website where anyone can view and contact posters without needing to be a member poses certain challenges. One of the main issues I face is the abundance of scam emails being sent to users, attempting to deceive them and steal their ...

The issue of font icons not displaying seems to be affecting all users

I have developed my own website that functions similar to fontawesome. However, after uploading it to an online server, I encountered a problem where others are unable to use my custom font icon. In order for someone to utilize the font icon from my websi ...

Highcharts 3D Pie Chart with Drilldown Feature

How can I create a 3D Pie Chart with Drilldown effect? I am having trouble understanding how it works. Here is a JsFiddle Demo for a 3D Pie Chart: JsFiddle Demo And here is a JsFiddle Demo for a 2D Pie Chart with Drilldown feature: JsFiddle Demo You can ...

calc() not supported on IE11

Why is IE11 unable to calculate this? The console shows it as invalid (highlighted in red) h6 { ... font-size: calc(calc((( (20 / 16) / 16 - 1 / 16) * (100vw - 20rem) / (992 / 16 - 20) + 1 / 16 * 1rem) * 16)); ... } However, the following code works ...

Tips for downsizing a large image to fit into a smaller area

I am working on a page layout that features a small circular navigation element. However, I am facing an issue with fitting a large picture within the boundaries of this small circle without it overflowing and causing alignment problems. Does anyone have ...

jQuery for Dynamic CSS Class

Is there a way to apply a different style to a link upon page load with jQuery? I would like the link to appear highlighted when the user navigates to a specific page, such as clicking on the About Us menu item. I want to use jQuery to achieve this effect. ...

"Patience is a virtue: Tips for waiting until a webpage is completely loaded using

I attempted to use a special class name that only shows up after the page has completely loaded, but for some reason it appears before the content is visible on screen. try: WebDriverWait(self.browser, 20).until(EC.element_to_be_clickable((By.CLASS_NA ...

The webpage fails to return to its original position after the script has been executed

My website has a sticky div that stays at the top when scrolling down, but does not return to its original position when scrolling back up. Check out this example function fixDiv() { var $div = $("#navwrap"); if ($(window).scrollTop() > $div.data("top ...

How to ensure MUI DataGrid fills the vertical space without any overflow issues

Trying to implement a MUI DataGrid within a Flexbox layout that fills the remaining space precisely can be quite challenging. Imagine a setup like this: --------------------------- | Header | --------------------------- | Table Header ...

I'm encountering an issue with VUEJS components including my show route in their get call. How can I make my journals/:id pages function properly without encountering a Mime

I encountered a MIME type error stating: Refused to apply style from 'http://localhost:8080/journals/assets/css/main.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. ...

What is the best way to eliminate unexplained spacing at the bottom of a webpage using CSS?

I am struggling to create a basic webpage using Bootstrap and D3, and I can't seem to figure out how to remove the excess whitespace at the bottom. Any tips on how to resolve this issue would be greatly appreciated. I attempted to set the min-height ...

Tips for inserting multiple numbers from a single row into separate options within a SELECT statement

Is there a way to create a select box with multiple options that are based on one row from my MySQL table? For example, <?php if(!empty($row['size'])) { ?> <label>Size</label> ...