Text animation in CSS3. Bring your content to a stylish halt

I'm looking for a solution to ensure that the border-based cursor stops at the end of the animated text rather than reaching the edge of the window. I have experimented with setting the width of the container and adjusting the text width, but since this will be used with variable widths, those solutions are not ideal.

<div class="type">
    <h1>We have some basic text here</h1>
</div>


body { background: #333; font-family: "Lato"; color: #fff; }

div.type {
  text-align: center;
  color: #fff;
  white-space: nowrap;
}

.type h1 {
  overflow: hidden;
  border-right: .05em solid #aaa;
  width: auto;
  text-align: center;
  margin: 0 auto;
  animation:
    type 5s steps(100, end)
}

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

Code Pen

Answer №1

Implementing max-width in place of width attribute.

.title h1 {
  display: inline-block; <-- included
  overflow: hidden;
  border-right: .05em solid #aaa;
  max-width: auto;
  text-align: center;
  margin: 0 auto;
  animation:
    title-anim 5s steps(100, end)
}

@keyframes title-anim {
  from { max-width: 0; }
  to { max-width: 100%; }
}

Visit the CodePen link for more details.

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

What is the best way to insert an image into an HTML card?

I'm a beginner in PHP and I'm working on creating a registration form that should have a design similar to the picture linked below: https://i.sstatic.net/7P7bn.png However, the form I've created so far looks like this: https://i.sstatic. ...

New feature in Bootstrap 4 beta allows carousel arrows to be positioned outside of the

I created a text-based carousel using Bootstrap 4 beta. Is it possible to move the arrows off of the slider area and position them outside of it? I have tried searching on Google and in other forums, but I couldn't find a solution. The issue is that s ...

What is preventing me from applying styles to the first word in my Angular ngFor iteration?

I'm currently attempting to customize the initial word of a string within my Angular ngFor loop. Strangely, the class gets applied but the style defined in my CSS file is not. Inline styling also does not seem to work - any ideas why? This is the CSS ...

Is it possible to incorporate percentage-based widths within a fixed layout design on a webpage?

I've been delving into the concepts of fixed, fluid, and responsive web page design. One of the resources I stumbled upon is this article about fixed vs. fluid layouts. In the article, it mentions that "A fixed website layout has a wrapper that is a f ...

Combining the lower margin of an image with the padding of a container: a step-by-step guide

There are two divs with a 50px padding, making them 100px apart. The top div contains an image floated to the right with paragraphs wrapping around it. The requirements team requests a 20px margin below the image if text flows under it, but no margin if th ...

What are the different choices available for incorporating a Bootstrap admin panel into a website?

After working on static HTML sites and dabbling in WordPress and Drupal for clients needing ecommerce features, I've decided it's time to up my game when it comes to content management systems. I want to move away from the usual options like Word ...

Unable to style table borders using CSS

I'm having trouble getting the borders to show up on my tables in my application. I added the "border: solid 2px black" line to my CSS, but nothing seems to be changing. Can anyone point out what I might be doing wrong? Here is my CSS: table { ma ...

How can JQuery determine the current CSS background image of a three-state icon or button?

I am facing a challenge with using three images to represent different states of an application icon, and I am trying to achieve this using CSS. There are no issues with the original or hover states: #myDIV { background-image: url(icons/homeBlack.png); } ...

Having difficulty in setting items to a relative position in order to align them properly

I am struggling to align two div items next to each other using Bootstrap. This is for a product detail view where I want the image on the left and text on the right. It's a product detail page for an ecommerce site that I'm trying to create. May ...

Tips for Adjusting the Position of a DIV Element Slightly Upwards

I am having trouble positioning the home-link image in my hovering navigation bar. The URL to my blog is: . Ideally, I want the image to be aligned with the text tabs next to it, but no matter what I try, I can't seem to move the "home" icon up by abo ...

Is there a way to prevent the text next to these FontAwesome icons from moving whenever the icon itself changes?

I am currently working on creating a unique custom checkmark using FontAwesome in my project. Below is the snippet of HTML and CSS style code that I am using: .check { font-size: 1.25rem; cursor: pointer; } .check-unselected { color: #4E44 ...

Creating a versatile table design using flexbox

Looking to create a gallery for images and videos using flexbox properties to create a dynamic table of divs to hold media. The challenge is generating the table automatically without specifying the number of rows and columns needed. For example, if I ha ...

Step-by-step guide on triggering a button using another button

I have a unique question that sets it apart from others because I am looking to activate the button, not just fire it. Here is my syntax: $("#second_btn").click(function(){ $('#first_btn').addClass('active'); }) #first_btn ...

Can someone provide details on how to reset the auto-scroll timer on my content slideshow after each click?

I'm currently building a content slideshow and you can find it at Below is the javascript code: jQuery(document).ready(function($) { setInterval(function() { moveRight(); }, 8000); var slideCount = $('#slider-isp ul li').length; ...

The content within an inline-block element exceeds the boundaries of its parent <pre> tag and causes overflow

I'm currently exploring ways to incorporate line numbers into text within a <pre> tag, all while maintaining the ability for the text to wrap. This presents some unique challenges: Adding line numbers in a separate column of a table is not an ...

Arranging Bootstrap 4 Right Column at the Top in Mobile View

My webpage is built using Bootstrap 4 and the layout looks like this: <div class="row"> <div class="col-md-8"> Content A </div> <div class="col-md-4"> Content B </div> </div> It displays ...

Bootstrap column links not functioning properly in IE/MS Edge upon page load

I recently encountered an interesting problem with my Bootstrap landing page. While it functions perfectly in Chrome and Safari, I discovered that some links cannot be clicked when using Microsoft's Edge Browser. You can view the live page at Slice V ...

AngularJS static list with dynamically changing content

Seeking inspiration on creating an AngularJS information monitor with a maximum of 6 rows. The display should show new rows at the top, pushing out the oldest row from the bottom when there are already 6 rows visible. Rows can also disappear unexpectedly. ...

move div upwards from the bottom

Within my HTML page, I have a centered div that measures 640x480. I am looking to create another div that appears from the bottom edge of the original div, with dimensions of 640x400. This means only the top 80px of the original div will be visible. I&apo ...

Is there a restriction on the maximum size of a CSS file?

Currently, I am working on building a site using ASP.NET MVC. The CSS file that I have been working on has now grown to 88KB in size and contains over 5,000 lines of code. Recently, I have noticed that some styles that I added towards the end of the file a ...