Home > Blockchain >  How do I hide the text that get out the div and get back to the start once the end of text was reach
How do I hide the text that get out the div and get back to the start once the end of text was reach

Time:11-01

I need to hide the text that got out the div, I've tried overflow: hidden; but it doesn't works... I also need to when the text reach the end, i.e., is seen <a href="'#">link8</a> some text 3!....<br><br> it get back to the start <a href="'#">link1</a> some text...<br><br> I have no idea how to try the form, I don't know much about CSS...

#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>

CodePudding user response:

I think you'd better use animation instead of transition. Here is my solution:

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;
}

@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>

In CSS, you can change the "top" value in example's "to" from the difference of #box and #container's heights. And I removed all css in the html code.

CodePudding user response:

try this , do not set position fixed. main div is relative and inner div is set as absolute position . like below example.

.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 >
            <div >
                <h2 >Scroll on Hover</h2>
                <div >
                    <div >
                        <img src="https://i.imgur.com/aFFEZ9U.jpg">
                    </div>

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

  • Related