CSS animation not working properly on mobile browsers due to custom code

I've been attempting to utilize a CSS animation as shown below, but I'm encountering issues in mobile browsers. This is likely due to setting overflow to hidden and white-space to no-wrap as part of the animation.

p {
  color: black; 
  white-space: nowrap;
  overflow: hidden;
  width: 100%;
  animation: type 5s steps(60, end);
  opacity: 0;
}

@keyframes type{
  from { width: 0; opacity:1;} 
  to { opacity:1;} 

Here is the JSFiddle link for the code https://jsfiddle.net/ed8nuf76/

Upon closer inspection, it appears that in mobile browsers, the entire sentence is not being displayed. Even on Fiddle, once the text reaches 100% width, instead of overflowing to a second line, it gets truncated.

Is there any solution to this issue?

Answer №1

If you're looking for a solution that doesn't require javascript, you can utilize the following pure-CSS approach - but keep in mind that you'll need to have an understanding of how many lines your content spans (as CSS alone cannot calculate this).

In the example provided below, by knowing that your content occupies 3 lines and each line has a line-height of 24px, you can specify to the animation that the container div should start at a height of 24px, grow to 48px after 1 second, expand further to 72px after another second, and finally reach a height of 96px.

You can then hide the lowest visible line of text within the div using an opaque ::after pseudo-element and apply a 1-second animation to it which repeats three times, with each repetition causing the pseudo-element's width to shrink from 300px to 0, gradually revealing the underlying text.

Here is a functional demonstration:

p {
margin-left: 6px;
font-size: 16px;
line-height: 24px;
white-space: nowrap;
overflow-x: hidden;
overflow-y: hidden;
animation: type 3s;
}

div {
position: relative;
width: 300px;
height: 96px;
padding: 0 6px;
overflow: hidden;
animation: growTaller 3s step-end;
}

div p {
margin: 0;
padding: 0;
font-size: 16px;
line-height: 24px;
white-space: normal;
overflow-x: hidden;
overflow-y: visible;
animation: none;
}

div::after {
content: '';
display: block;
position: absolute;
bottom: 0;
right: 0;
z-index: 6;
width: 312px;
height: 24px;
background-color: rgb(255,255,255);
animation: typeFaster 1s linear 3;
}

@keyframes type {
from {width: 0;} 
to {width: 100%;} 
}

@keyframes typeFaster {
from {width: 312px;} 
to {width: 0;} 
}

@keyframes growTaller {
0%   {height: 24px;}
33.33%  {height: 48px;}
66.66%  {height: 72px;}
100%  {height: 96px;}
}
<p>Hi folks, this is typing animation using CSS, I want this to run in mobile browsers without breaking.</p>

<div>
<p>Hi folks, this is typing animation using CSS, I want this to run in mobile browsers without breaking. Using this method, it works!</p>
</div>

Answer №2

The issue doesn't lie with the mobile browsers themselves, but rather it is related to them due to a simple factor: the width's space.

In this scenario, the width of the text container is determined by the length of the text being utilized. This means that even if you set the width to 100%, you are still limited by the total width of the browser device. Additionally, CSS3 alone does not have the capability to handle line breaks logically.


Optimal solution: utilize JavaScript to manage these logical elements.

There are several excellent options available that can handle this task effectively and easily:

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

The 'import' statement is not functioning properly within a script in the rendered HTML

While working on an express application, I've encountered a recurring error that I can't seem to solve. The error message is: "GET http://localhost:3000/javascript/module2 net::ERR_ABORTED 404 (Not Found)" Could someone kindly assist me in ident ...

When employing a string union, property 'X' exhibits incompatibility among its types

In my code, I have two components defined as shown below: const GridCell = <T extends keyof FormValue>( props: GridCellProps<T>, ) => { .... } const GridRow = <T extends keyof FormValue>(props: GridRowProps<T>) => { ... & ...

Issue with texturing custom geometries in three.js: custom geometries are

There are two custom geometries that I created: Box2Geometry and StaticTestPentagonPlaneGeometry. The Box2Geometry JSFiddle shows that the first geometry texturizes perfectly, while the StaticTestPentagonPlaneGeometry JSFiddle does not texturize properly. ...

Javascript tip: Place brackets within braces when declaring an array

Recently, I came across a code snippet that is new to me and I'm having trouble finding an explanation for it online: function segColor(c) { return { red: "#FF0000", green: "#00ff00", blue: "#0000ff" }[c]; } I'm ...

The browser is unable to access localhost:3000

Backend: Utilizing an Express server, created with the npx create-express-api command Frontend: Using Next.js, set up with npx create-react-app in the frontend directory Having executed these commands in the root folder, I attempted to run npm start xxx ...

Error: The function $(...) does not contain a progressbar

I encountered a TypeError saying $(...).progressbar is not a function when loading the Gentelella - Bootstrap Admin Template Page. This error is affecting many jQuery processes. How can I resolve this? Error in my Code: (custom.js) // Progressbar if ($( ...

Modifying column layout within an HTML webpage

I'm seeking advice on modifying a code. I'd like to keep it the same as it is now, but with one change - I want to decrease the width of the main video box and add another one beside it with an iframe code for a chatbox. Here's the current c ...

What is the process for changing the background color with Angular?

It should be a straightforward task, but for some reason, it just won't cooperate. Within my controller: $scope.projects = [ //... { background: "#ffffcc" }, //... ]; In the HTML: <div ng-repeat="project in projects" ng-style="{ ...

What is the best way to showcase a product's star rating using a variable or input from the user?

I'm seeking a solution to dynamically display a star rating in Spring Boot/Java without specifying a fixed value. While I can show star ratings with a set value, how can I update the rating based on an average of user ratings? Most tutorials only cove ...

What is the best approach to place a label between the jqm rangeslider and the sliderthumb?

My goal is to place the label between the slider and the slider thumb in order to maximize screen space utilization. However, I am facing an issue where the label appears above everything and I am unable to resolve it using z-index... HTML: <div class ...

Enhance Your YouTube Comment Section with CSS Styling

I am brand new to css html and I'm attempting to create a comment display system similar to that of YouTube using only CSS. My goal is to have an image of the commenter displayed, followed by their username and comment text listed beside it. So far, I ...

Is there a method to track the progress of webpage loading?

I am working on a website built with static HTML pages. My goal is to implement a full-screen loading status complete with a progress bar that indicates the page's load progress, including all images and external assets. Once the page has fully loaded ...

Is setting the height to 100% a dependable option for container loading during the initial page rendering in CSS?

Upon arrival on the page, I envision the container containing the "search" to expand and occupy the entire screen. Seems simple enough: just set the height to 100%. If the user chooses to scroll down, they will see the rest of the content. It almost fee ...

Using Websockets in combination with AngularJS and Asp.net

While working on my application that uses AngularJS with Websocket, I encountered a specific issue. The WebSocket communication with the server works fine as users navigate through different pages in Angular. However, when a user decides to refresh the p ...

The mysterious Vue.js and Nuxt.js custom element

Encountering an issue https://i.sstatic.net/imRbe.png Seeking assistance with identifying my mistake. Attempting to create reusable components, starting with a button for example. I have created it in the file path: /components/MusicPlayer.vue: <temp ...

Mastering the art of utilizing $.get(url, function(data) in pure JavaScript

I am currently exploring how to achieve the equivalent of $.get(url,function(data) { code }; in pure JavaScript. function fetchImage(keyword){ if(!ACCESS_KEY){ alert("Please update your access key"); return; } var request = new XMLHttpRequ ...

Styling tables within HTML emails for Gmail and then utilizing PHPMailer to send the emails

I've been racking my brain over this for hours with no luck! Objective: Implementing inline styles for table, td, th, p elements in an HTML email intended for Gmail using PHPMailer. Challenge: Inline styles not being rendered HTML Snippet: <sec ...

Clipped Words & Silhouettes

I'm having trouble ensuring the text in this particular example displays correctly. I am experiencing challenges with the clipping of text and shadows on certain letters, and I'm struggling to identify the root cause as well as the solution. In ...

Received a notification after submitting an HTML form

<html> <body> <form action="" method="GET> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> <?php if( $ ...

Which should take precedence: EffectComposer or Z-Buffers in rendering?

Currently, I am in the process of constructing a network graph through the use of Three.js, which involves creating numerous nodes and connecting lines. My main objective is to ensure that the lines always appear behind the nodes, particularly because the ...