Challenge with displaying spans in Chrome browser

I am currently facing an issue with a running news ticker that displays correctly in Firefox but not in all versions of Chrome:

<div id="a" style="position:fixed; bottom:50px; height:30px;">
  <span id="b" style="display:inline; position:absolute;">blah blah text one two three.</span>
</div>

Upon loading the document, I utilize a jQuery function to set the CSS properties (specifically adjusting the left positional value of #b) so that the text moves from right to left. Once the text is completely off the screen, I reset the left positional value of #b back to screen.width.

However, in Chrome, the text of #b gets cut off to only 1-2 words and remains broken into multiple lines without changing back (unlike in Firefox where it shows correctly like a news ticker). After doing some investigation, I discovered this behavior in Chrome and was wondering how I can avoid it or if this is a bug specific to Chrome.

Answer №1

Upon testing in Opera, I observed the text breaking into multiple lines, suggesting that this issue may not be exclusive to Chrome. To resolve the multi-line problem, I removed the position: absolute property. However, it raises the question of whether this position is necessary for animations.

EDIT: Further investigation revealed that the issue is not related to positioning. The problem stems from element a lacking width, causing the browser to reduce the width of element b to a minimum. Adding a width attribute should rectify this issue. For optimal results, a width slightly exceeding 100% is recommended to accommodate the hidden b. Below is an example demonstrating this solution with a width of 200%, which functions correctly on Opera, Firefox, and Chrome.

<html>
<body>
<script language="javascript">
var pos = innerWidth;
function setTimer() {
    b = document.getElementById('b')
    pos = pos - 10;
    if(pos <= 0)
        pos = innerWidth;
    b.style.left = pos+"px";
    setTimeout(setTimer,100);
}

</script>
<button onclick="setTimer()">start</button>
<div id="a" style="position:fixed; bottom:50px; height:30px; background-color: gold; width:200%">
  <span id="b" style="position:absolute; background-color: teal">blah blah text one two three.</span>
</div>
</body>
</html>

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

Having trouble with jQuery Ajax partially view rendering more than once?

I have encountered an issue with my asp.net page where it returns a partial view within the current tab I am working in. Initially, my jQuery setup works perfectly fine - the ajax call retrieves and displays the partial view using .html(result); However, ...

What is the process for altering the CSS path within an HTML helper in CakePHP 3.x?

I am trying to access the admin-css: echo $this->Html->css('adminStyle'); <link rel="stylesheet" href="/css/adminStyle.css" /> However, I would like it to be as follows: <link rel="stylesheet" href="/admin/css/adminStyle.css" /& ...

Tips for displaying unformatted text using HTML

Is there a way to display a string in HTML with all of its escape sequences preserved? For example: eipt No. : 1995,\nmount 935\nAdm. : 17/06/2016 INSTRUCTIONS : 1) This card is valid only for the student's name & for the period indic ...

Sending Values from Google Apps Script to HTML Elements

I'm trying to figure out how to transfer the 'MyLink' variable from my Google Scripts Code to HTML code. Below is the snippet of the GS Code: function FirstView(){ var ss = SpreadsheetApp.getActiveSpreadsheet(); var MyNewBook = ss.copy ...

Enhance form validation by utilizing jquery.validate to display appropriate icons indicating correct and incorrect input, with the option to

Trying to replicate the functionality of the jQuery validate plugin demo seen here, I am facing an issue on my own website. Upon clicking submit after the page loads, the plugin displays validation messages with a cross symbol. However, upon entering text, ...

Tips for effectively triggering an animation only once when the element is in view using React

I'm just starting out with React and I want to trigger a CSS @keyframes animation when my element enters the viewport. To achieve this, I am using the Intersection Observer with the help of the useOnScreen hook from Here is my JSX : import React, {u ...

Is there a way to submit a form without navigating away from the current webpage?

I'm working on a registration form and I need help figuring out how to send the input information to the action.php file without the user being redirected to it. Is there a way to have the form submitted in the background and then redirect the user ba ...

Insert an svg element into the content property

Is it possible to insert an SVG link within the content property? .selectedItem::before{ content: " any svg link "; ...

Transfer data from one table to another on a different PHP page

I'm currently working on a school project that involves creating a web retail store where products are fetched from a database using PHP. Users are able to select items by checking a checkbox and then proceed to add them to their cart. The challenge I ...

What is the method for assigning a custom CssClass to the THEAD element within a dynamically generated HTML table?

Utilizing Bootstrap 4 gives me the opportunity to incorporate a unique style for the table header. By following this syntax: <table class='table table-bordered'> <thead class='thead-dark'> <!-- etc --> ...

Develop a stylish HTML/CSS box featuring a trio of diagonal gradient colors

Trying to achieve a square with three colors inspired by the concept of a Two-tone background split by diagonal line using css, but with an additional color scheme similar to this example: https://i.sstatic.net/ci2Zv.png Seeking advice. Attempted the fol ...

Issue with background repetition in CSS

I'm looking to stretch a background image along the left margin of my webpage. Here's the CSS I'm using: body, html{ height:100%; } #content{ background:url(../images/leftBorder.png); background-repeat:repeat-y; height:100% ...

Can you assist in resolving this logical problem?

exampleDEMO The code above the link demonstrates how to control input forms based on a button group selection. In this scenario, when a value is inputted on the 'First' Button's side, all input forms with the same name as the button group ...

Reposition the element at the bottom of its parent element

I am facing an issue with the HTML structure in my application: <div class="work-item"> <div class="image-container"> </div> <div class="text-container"> </div> </div ...

Including tabs from a different HTML page within a tab on my own HTML page - enhancing the user interface of a web application

I am currently developing a web application with 4 tabs. Each tab includes a side menu (created using jQuery) and the rest of the space is divided into two sections: top div and bottom div (a table with two columns - column 1 contains the side menu, and co ...

"Bootstrap4 - Troubleshooting the Issue of Multiple Carousels Not Function

I attempted to incorporate 2 Bootstrap 4 carousels onto a single page, but encountered issues with the functionality. I utilized this code on my page, however, the last element in the carousel does not cycle correctly. There is a delay of 3 transactions be ...

Learn how to create a horizontally scrollable ToggleButton using MUI when the ToggleButtonGroup exceeds the screen width

Looking to enhance the responsiveness of my web design project, I aim to create a horizontally scrollable ToggleButton using Mui. The goal is to have the buttons adjust when the screen width becomes too narrow to display all three buttons at once, allowing ...

Obtain the beginning and ending positions of a substring within a larger string

As a beginner in the world of AngularJS and web development, I am faced with a challenge. I have a specific string that is currently selected on a tab, like so: var getSelectedText = function() { var text = ""; if (typeof window.getSelection !== "un ...

Tips for transferring information from a form to your email address

I am trying to find a way to automatically send form data to my email without the user having to open their inbox. I attempted to use the "mailto" function but it didn't work as desired, still opening the email box. Here is the script I tried: functio ...

"Encountering an error of undefined index when dealing with multiple file

I've encounter an issue with this code but can't seem to figure out what's wrong. Any help would be greatly appreciated. Kindly refrain from marking it as a duplicate too quickly; I've already gone through similar questions without find ...