Conceal excess text during auto-scrolling without removing it

I am looking to conceal extra text within a child div without fully deleting it or forcing it into a vertical orientation. I want the excess text to be revealed gradually, similar to how Spotify and Apple Music handle it.

My goal is for the red div to act as a "mask" for my child h3. I attempted changing the div to relative positioning, but that caused the text to display vertically, which is not what I desire.

Below is the code snippet:

.example1 {
  margin-left: 100px;
  height: 50px; 
  width: 100px;
  border: 10px solid red;
}
.example1 h3 {
    position: absolute;
    width: auto;
    margin: 0;
    line-height: 50px;
    text-align: center;
    border: 10px solid black;

/* Starting position */
transform:translateX(50%);

/* Apply animation to this element */  
animation: example1 20s linear infinite;
}

/* Move it (define the animation) */
@keyframes example1 {
0%   { 
transform: translateX(0%);         
}
100% { 
transform: translateX(-50%); 
}
}
<div class="example1">
<h3>This is a really long title that doesn't fit</h3>
</div>

Answer №1

Here is a solution with the implementation of flex-box for text centering.

.example1 {
    width: 200px;
    height: 50px;

    border: 10px solid black;
    overflow: hidden;
    
    display: flex;
    flex-flow: column nowrap;
    justify-content: center;
}

h3 {
    transform: translateX(100%);
    animation: horizontal-scroll 20s linear infinite;
    width: max-content;
    margin: 0;
}

@keyframes horizontal-scroll {
    to {
        transform: translateX(-100%);
    }
}
<div class="example1">
   <h3>This is a really long title that doesn't fit</h3>
</div>

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

Customize the width of grouped input fields in Bootstrap without relying on the grid system

I recently attempted to construct fields with combined input in Bootstrap. Despite successfully doing so, I am now faced with the challenge of setting the width of the input boxes. <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/b ...

Is there a way to display a Bootstrap popover for a button when another button is clicked?

Is there a way to manually display popovers instead of triggering them on element click events? Below is an example code snippet featuring two buttons: Click me: displaying popover upon clicking. (this should not occur) Show click me popover: intended ...

Display fixed or absolute elements within a scrollable container

I want to create a unique design with overlapping divs that can be selectively displayed through scrolling. While this effect is possible with images using background-attachment: fixed, I am seeking a solution that can work for any child element. Here is ...

Transferring data from JavaScript to an HTML page

I'm currently developing a rock, paper, scissors game using HTML and JS. Here is the link to the complete code (CSS, JS, HTML): http://jsfiddle.net/fJw4R/. You can also view the game with images here: The functionality of the .math-module is working ...

Exporting table data from Bootstrap 3 DataTable to Excel is not functioning as expected

I am attempting to export the data from a table to MS Excel by referring to this example: https://datatables.net/extensions/buttons/examples/styling/bootstrap.html While the content displays correctly on the page, the issue arises when I try to export it. ...

Resolving the Smooth Scrolling Problem

Here is a simplified version of what I am currently working on: Although I have managed to get the scrolling functionality to work, there seems to be an issue with transitioning from one section to another. For example, when clicking on NUMBER 3, it s ...

What causes Font Awesome 5 icons to vanish when changing the font-family?

I am facing an issue with the code I have below. It changes the font style successfully, but it also causes the icon to disappear. Can anyone provide tips on how to ensure that the icon remains visible while changing the font style? <link rel="styles ...

Ways to serve HTML without relying on code generated by JQuery

I am currently utilizing the html() function in JQuery to extract the HTML content of a specific div on my web page. Nevertheless, the output includes all the code generated by JQuery as well: <ul><li id="fact_1" class="jstree-open"><ins cl ...

The JavaScript function may fail to work if the AJAX request is not completed

Upon completion of my ajax request, my function does not seem to be functioning as expected. Here is the script I am using: <script> function sendmsg(id,msg){ alert('id is'+id+'and msg is '+msg); } <scr ...

Integrate JavaScript with WordPress

How can I get this functioning properly within Wordpress? I have been attempting to connect everything together, but it doesn't appear to be working. Is this the correct way to do it, or am I overlooking something? <script type="text/javascript" s ...

Struggling with the complexity of SASS gradients mixin

After spending over two hours chasing my tail, I'm still struggling to create a cross-browser gradient @mixin. My desired result is: -moz-linear-gradient(left, #fff 0%, #000 100%); Using the default arguments in: @mixin gradient($type:linear, $gra ...

Showcasing Wordpress blog entries on another webpage

Struggling with understanding how to showcase posts from a Wordpress blog on a website? You're not alone. Imagine you have a website www.site.com and a blog structured in Wordpress located at www.site.com/blog. Your task is to feature the recent post ...

What is the process for creating a sublist within an md-list-item using Angular Material?

I used Angular Material to create a md-list on the side-nav. I am looking to add a sub list under the md-list-item. Below is my code snippet: <md-sidenav id="sideNav" md-component-id="left" class="md-sidenav-left md-whiteframe-z1 md-locked-open " layo ...

The table's pagination displays above, thanks to Tailwindcss

I'm facing an issue where the pagination is showing up above the table, but I was expecting it to be displayed after the table. It would be ideal if the pagination appeared right after the table when adding multiple rows. Check this link for more inf ...

Stack one image on top of another while maintaining their original proportions using HTML and CSS

I have two images, one is used as a background (A) and the other (B) is positioned over a portion of the background. The issue I am facing is that when the resolution changes, the image B moves and is no longer in the desired position. https://i.sstatic.ne ...

On a Samsung tablet with Moodle, the body background image is set to display at the top

Encountered an issue with Sambungs tables. I have a background image set on the body. Here is how the CSS looks: html, body{ background: url('img/background.jpg') no-repeat; background-position: top; // I also tried cover, fixed, etc } The ...

What could be the reason that the results of my quick sort function are not appearing on the screen

I'm having trouble getting any output from this code. Can someone help me figure out what's wrong? function Ascending() { var array = new Array(); array[0]=parseInt(document.getElementById("1").value); array[1]=parseInt(document.getElementById(" ...

Tips for including an external babel JS (ES6) file in an HTML document:

To include the babel js file in an HTML file, take a look at the code snippet below: <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudfl ...

Search for text within the nearest <p> tag using HTML and jQuery

My table contains different td elements with the same ID, as shown in this foreach loop: <td class="AMLLeft" style="display:inline-block; !important">ID: <p class="important">${item.id}</p> </td> <td align="right" nowrap="tr ...

What is the best way to convert this html code into php?

I’m trying to figure out how to incorporate all of this into my loop, but I’m not sure if it can be broken up. However, PHP needs to interpret it as HTML. $movieDetails = <header class="masthead" role="banner"> <div class="logo-con ...