What is the best way to conceal text that overflows from a div and seamlessly return to the beginning once the end of the text has been reached?

I am struggling to figure out how to hide the overflow text that is spilling out of the div. I attempted using overflow: hidden;, but unfortunately, it didn't work as expected. Additionally, I would like the text to loop back to the beginning once it reaches the end, for example, displaying

<a href="'#">link1</a> some text...<br><br>
after showing
<a href="'#">link8</a> some text 3!....<br><br>
. My CSS skills are limited, so any guidance on how to achieve this would be greatly appreciated.

#container {
  position: fixed;
  font-size: 20px;
  transition: .2s;
  margin-top: 10px;
  transition: margin 1s;
}

#box:hover #container{
  overflow: hidden;
  margin-top: -3500px;
  transition: margin 400s linear;
}
  <div style="background-color: rgb(162, 0, 255); height: 400px;" id="box">
    <div id="container">
        <a href="'#">link1</a> some text...<br><br>
        <a href="'#">link2</a> some more text 2....<br><br>
        <a href="'#">link3</a> some text 3....<br><br>
        <a href="'#">link4</a> some text 3....<br><br>
        <a href="'#">link5</a> some text 3....<br><br>
        <a href="'#">link6</a> some text 3....<br><br>
        <a href="'#">link7</a> some text 3....<br><br>
        <a href="'#">link8</a> some text 3!....<br><br>
    </div>

Answer №1

I suggest using animation instead of transition for a smoother effect. Here's how you can implement it:

CSS:

#box {
    background-color: rgb(162, 0, 255);
    height: 300px;
    position: relative;
    overflow: hidden;
}

#container {
    position: absolute;
    font-size: 20px;
    top: 10px;
}

#box:hover #container {
    overflow: hidden;
    animation-name: example;
    animation-duration: 5s;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}

@keyframes example {
    from {
        top: 10px;
    }
    
    to {
        top: -65px;
    }
}

HTML:

<div id="box">
    <div id="container">
        <a href="'#">link1</a> some text...<br><br>
        <a href="'#">link2</a> some more text 2....<br><br>
        <a href="'#">link3</a> some text 3....<br><br>
        <a href="'#">link4</a> some text 3....<br><br>
        <a href="'#">link5</a> some text 3....<br><br>
        <a href="'#">link6</a> some text 3....<br><br>
        <a href="'#">link7</a> some text 3....<br><br>
        <a href="'#">link8</a> some text 3!....<br><br>
    </div>
</div>

You can adjust the value in the "to" section of the example keyframe based on the height difference between #box and #container. I have also removed all inline CSS from the HTML code for better organization.

Answer №2

Here is a suggestion: instead of using position fixed, try setting the main div as relative and the inner div as absolute position. Take a look at the example below.

.container {
  padding: 80px 0;
}
.content {
  position: relative;
}
.screen {
    display: block;
    width: 300px;
    height: 350px;
    overflow: hidden;
    position: relative;
    border: 2px solid #b3b3b3;
    border-radius: 1px;
    margin: 0 auto;
}
.screen img {
    bottom: -1210px;
    width: 100%;
    height: auto;
    position: absolute;
    z-index: 0;
  margin:0;
  padding:0;
    -webkit-transition: top 11s;
    -moz-transition: top 11s;
    -ms-transition: top 11s;
    -o-transition: top 11s;
    transition: bottom 11s;
}
.screen:hover img {
  bottom: 0;
  -webkit-transition: all 11s;
  -moz-transition: all 11s;
  -ms-transition: all 11s;
  -o-transition: all 11s;
  transition: all 11s;
}
<div class="container">
            <div class="row">
                <h2 class="text-center">Scroll on Hover</h2>
                <div class="col-md-4 col-md-offset-4 content">
                    <div class="screen">
                        <img src="https://i.imgur.com/aFFEZ9U.jpg">
                    </div>

                </div>
            </div>
        </div><!--container-->

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

Styling an image with dual attributes using CSS

I'm looking to customize two img classes with different properties. For instance, in my CSS, I want to define: img { padding-left: 15pt; float: right; } and then: img1 { padding-left: 15pt; float: left; } where img1 would serve as a tag fo ...

Creating Child Components Dynamically using String Names in ReactJS

I've encountered an issue with dynamically rendering React Components within my DashboardInterface component. I have an array filled with string names of React Components, retrieved through an external mechanism. The goal is to render these Components ...

Guide on updating individual rows in Google App Script using data from a different sheet

I am trying to create a script that will pull a value from column[3] in the ZONE sheet to the active sheet, specifically in column 56 of the job sheet when the zonelist value matches the zone value in different sheets. The script should check the range fro ...

Creating a dynamic JSTree that loads data on demand using Stored Procedures

Currently in my SQL Server database, I have two Stored Procedures that are responsible for extracting data from a tree structure: One procedure retrieves all nodes at a specific level based on the provided level number. The other procedure retrieves th ...

Changing a string to HTML within an Angular 2 application

Is there a simple way to convert a string to HTML? I am attempting to convert a string containing valid HTML, href links, and line breaks. Currently, I am utilizing the DOMParser().parseFromString method as outlined on https://developer.mozilla.org/en-US ...

JavaScript Bug Report

Currently, I am immersed in a project that encompasses various languages like HTML, JS, and PHP. While working on one of the PHP functions, I stumbled upon an unexpected anomaly. To dissect it better, I decided to break it down into simpler functions: &l ...

A different and more efficient way to address the issue at hand

During a recent interview, I was asked the following question and despite being able to solve it, the interviewer pointed out that my code was not optimized. Is there anyone who can help me with an optimized solution? Question : Given an array array1, rea ...

Contrast between the structure of asp.net button and hyperlinks

I want to transfer the styles of a hyperlink in regular html to an Asp.net button. However, I encountered a strange background issue that is disrupting the appearance of the buttons. Hyperlink: Asp.net Button How can I remove the outline that appears o ...

Unable to adjust the width of a label element using CSS specifically in Safari browsers

Here's the issue I'm facing with my HTML code <input type="checkbox" asset="AAA" name="assets[AAA]" value="AAA" id="assets[AAA]" class="c_green" checked="checked"> <label for="assets[AAA]"></label> In my CSS, I have the follow ...

What is the correct method for service injection in Angular 8?

I have encountered an issue while trying to inject a service into my main "App" component. The error message is shown in the screenshot below: constructor(private newsApi: NewsApiService) {} Upon importing the service using the code above, I received the ...

Analyzing latency in node.js through numerous requests

Is there a way to send multiple requests in a loop, and measure the time of each request? In PHP I'd do: require 'vendor/autoload.php'; use GuzzleHttp\Client; $client = new Client(); for ($i = 0; $i < 100; $i++) { $start = mic ...

Is it possible to utilize the cv.imencode function in Opencv.js for exporting images in the webp format?

I'm looking to convert images from various extensions like png and jpg to webp format. I initially explored using OpenCV.js but was unable to locate the cv.imencode method for creating webp images. Can anyone confirm if this method is supported? If no ...

Modify the color of a unique word within a cell in a gridview

How can I change the color of specific keywords in a gridview cell without affecting all words? Here is the sample code: protected void gvContents_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) ...

Having trouble uploading images using ReactJS on the web platform

I am currently in the process of developing a portfolio website using react js, but I'm experiencing an issue where the image I intended to display is not showing up on the live site. Despite thoroughly checking my code, I can't seem to identify ...

It is advised not to use arrow functions to assign data when fetching API data with axios in Vue.js 2

Trying to retrieve data from a URL using Axios in my Vue app is resulting in the error message: Error: Arrow function should not return assignment Complete error message: Error: Arrow function should not return assignment (no-return-assign) at src\co ...

Unable to dial phone numbers when clicking 'Click to call' link on Android devices

Within my Cordova android application, I have a link set up like this: <a href = "tel:011123456789">Click to Call</a> While this click-to-call functionality works smoothly in IOS, it seems to be hindered in Android by an issue such as: 11- ...

Creating Email Designs with Multiple Layers for Outlook Versions 2007 and 2010

I hope you're all having a fabulous Aloha Friday! I have a question regarding HTML emails, specifically in relation to Outlook 2007 and 2010. Currently, I am working on a project that involves layering a couple of PNG images on top of each other, wel ...

Tips for displaying server data in a graph format

I am currently working on a project that involves using PHP: In this project, users will input their health data and upload it to the server, assuming the server is on a local host. My main question now is how can I effectively present this data to the u ...

Prevent scrolling on browser resize event

I am working on a basic script that adds a fixed class to a specific div (.filter-target) when the user scrolls beyond a certain point on the page. However, I am wondering how I can prevent the scroll event from triggering if the user resizes their brows ...

Angular2 Error: Cannot have two identifiers with the same name, 'PropertyKey' is duplicated

I am currently developing an application with angular2 using angular-cli. Unfortunately, angular-in-memory-web-api was not included by default. After some research, I manually added the line "angular-in-memory-web-api": "~0.1.5" to my ...