Animation of a typewriter erasing a section of a letter

I have implemented a typewriter animation effect using the code from this source (link provided). I intentionally set everything to slow speed for better clarity. The animation works fine, but there is an issue where each letter that appears on the screen gets partially erased by the cursor on its right. Is there a way to resolve this using only CSS or do I need to incorporate JavaScript? Thank you.

/* Google Fonts */
@import url(https://fonts.googleapis.com/css?family=Anonymous+Pro);

/* Global */
html{
  min-height: 100%;
  overflow: hidden;
}
body{
  height: calc(100vh - 8em);
  padding: 4em;
  color: rgba(255,255,255,.75);
  font-family:'Anonymous Pro' ,monospace ;  
  background-color: black;  
}
.line-1{
    position: relative;
    top: 50%;  
    width: 24em;
    margin: 0 auto;
    border-right: 4px solid green;
    font-size: 180%;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    transform: translateY(-50%);    
}

/* Animation */
.anim-typewriter{
  animation: typewriter 100s steps(44) 1s 1 normal both,
             blinkTextCursor 1000ms steps(544) infinite normal;
}
@keyframes typewriter{
  from{width: 0;}
  to{width: 24em;}
}
@keyframes blinkTextCursor{
  from{border-right-color: green;}
  to{border-right-color: transparent;}
}
<!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <link href='https://fonts.googleapis.com/css?family=Electrolize' rel='stylesheet'>
    <title>
    Test
    </title>
    </head>
    <body>
    <p class="line-1 anim-typewriter">Animation typewriter style using css steps()</p>
    </body>
    </html>

Answer №1

When utilizing a monospace font, it is important to take into account the ch unit to establish the width, as 1ch represents the width of one character. Additionally, make sure to adjust your step by including start.

/* Using Google Fonts */

@import url(https://fonts.googleapis.com/css?family=Anonymous+Pro);

/* Global styling */

html {
  min-height: 100%;
  overflow: hidden;
}

body {
  height: calc(100vh - 8em);
  padding: 4em;
  color: rgba(255, 255, 255, .75);
  font-family: 'Anonymous Pro', monospace;
  background-color: black;
}

.line-1 {
  position: relative;
  top: 50%;
  margin: 0 auto;
  width: 0;
  border-right: 4px solid green;
  font-size: 180%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  transform: translateY(-50%);
}


/* Animation effects */

.anim-typewriter {
  animation: 
   typewriter 45s steps(44,start) 1s forwards, 
   blinkTextCursor 0.3s steps(15) infinite;
}

@keyframes typewriter {
  from {
    width: 0;
  }
  to {
    width: 44ch;
  }
}

@keyframes blinkTextCursor {
  from {
    border-right-color: green;
  }
  to {
    border-right-color: transparent;
  }
}
  <p class="line-1 anim-typewriter">Creating a typewriter-style animation using CSS steps()</p>

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

Tips for choosing a sibling element on hover using CSS

I'm having trouble figuring out how to make the rect element change color to purple when the text is highlighted. Right now, only the text color is changing. Is there a way to achieve this using just CSS? The goal is for the rect to turn purple on ho ...

The issue with the left border color not functioning in JavaScript

Attempting to alter the border-left-color property using this script is resulting in a Uncaught SyntaxError: Unexpected token -. Is border-left-color actually supported? Javascript function logoChange() { var description = new Array (); description[0] ...

Creating a unique carousel design using only CSS in Bootstrap

Trying to create a CSS effect to enhance Bootstrap, I noticed that it only works correctly when clicking the right arrow. Whenever I click the left one, nothing happens. I'm not sure where I made a mistake, can anyone help me spot it? Thanks in advanc ...

Squarespace | Tips for Completely Removing the Footer in the Pacific Template

I must say, the footer on this website is incredibly stubborn. Let's take a look at subject A: URL: Hello there! I'm currently working on a website and I'm facing a challenge with the background not stretching to fit the entire window when ...

Comparing Embedded and Linked JS/CSS

In my experience, I understand the advantages of using linked CSS over embedded and inline styles for better maintainability and modularity. However, I have come across information suggesting that in certain mobile web development applications, it may be m ...

Utilizing CSS inheritance in React app to style multiple classes simultaneously

My app features two buttons that serve similar functions on different pages. One button directs users to the search page, while the other takes them back to the home page. The challenge I'm facing is that I need the background image for each button t ...

Tips for adjusting the page display when errors occur during form submission

Within my django application, I have designed a page featuring a button that controls the operation of a clock. Initially, the page displays only the button, with a hidden form where users can input details such as their name and description. When the butt ...

Concealing a form after submission using JavaScript

After submitting the form, I am attempting to hide it and display a loading GIF. I've experimented with various methods, including changing ClassName to Id, but haven't had success. This is for a school project, and I've spent a significant ...

Using jQuery to create overlapping images

Currently, I am working on an effect that involves overlapping images. The idea is that when a bar is clicked and dragged, the image underneath should reveal by adjusting its width. While my code functions, there are some glitches present. One issue is tha ...

When converting with wkhtmltopdf, elements may lose their original positioning

I am currently using wkhtmltopdf to create a .pdf file for printing HTML code. However, I am facing an issue where the HTML elements are getting rearranged and not staying in their original positions when I generate the pdf. Here is my code snippet for ge ...

Adding text on top of an image

I am having trouble with the master slider plugin as slide1, 2, and 3 each have unique classes. I attempted to overlay text on the image but it is not showing up. I tried using the following CSS code but nothing appeared on the screen. .classnameslide1: ...

Styling React tabs using Material UI CSS

Here is an image of the screen I've developed with React Material UI tabs: https://i.sstatic.net/suzmB.png The screen features two tab headings: Contribute component and Contribute idea. I am looking to reduce the size of these buttons without affect ...

Issue with Bootstrap navbar failing to collapse on iOS devices

I have been working on a website using Bootstrap and everything seems to be running smoothly. However, I've encountered an issue where the navbar doesn't collapse when viewing the site on my iPhone. It works perfectly fine when viewed on my Windo ...

The issue with EJS Header and Footer not showing up on the

I am currently building a basic todo list application using EJS. However, I am encountering an issue when running it. I would like to run app.js with the header and footer in EJS, but it seems that it is not recognizing the header despite using what I beli ...

Switching back and forth between classes prevents the animation from playing continuously, causing it to jump straight to the end

Currently, I am in the process of animating a hamburger menu with a unique twist. The idea is to have the top and bottom lines smoothly translate to the middle and then elegantly rotate into an X shape when clicked. My approach involves toggling between tw ...

Adjust the hue of the SVG sprite

I am currently using an SVG sprite as the background image for my project: .naar-logo { background: url(images/salt_sprite.svg) no-repeat -8px -78px; width: 36px; height: 49px; position: relative; top: 38px; } <div class="naar-logo ...

Is there a way to modify a CSS class in Chrome that is only visible when I perform a drag action?

For the website project I am working on, I have an element that only changes its style when I drag something over it. This is achieved by adding a CSS class to it. However, editing this style has proven to be challenging because I cannot live edit it in C ...

Flipboard-inspired CSS Animation

I have been following a tutorial regarding CSS flip effects and encountered some challenges. The tutorial can be found here. .flip-container { perspective: 1000px; } /* add more code here... */ <div class="flip-container" ontouchstart="th ...

It appears that Internet Explorer is still animating/processing my loading.gif despite being set to display:none

It seems that the issue I'm encountering is related to the inconsistent starting position of the loading.gif animation when performing an ajax request. In Internet Explorer, the animation appears to start from a random point, while in Firefox it alway ...

Issue regarding the sidebar's top alignment

Having trouble with the positioning of this sidebar. It seems to be hanging slightly over the top edge instead of aligning perfectly with it. Here's how it looks: enter image description here. CSS CODE: https://pastebin.com/RUmsRkYw HTML CODE: https ...