I'm trying to make a text visible to the user only when it is inside the div, while it must be hidden when it is out of the div.
The text is animated from left to right, so it's not fixed.
It's pretty hard to explain, so i made a image to make you understand better:
Basically everything else except the div and the box should have a higher z-index to obtain this effect, but that's impossible because it would cover everything .
Any idea, possibly using CSS and JS or JQuery?
I'm trying to make a text visible to the user only when it is inside the div, while it must be hidden when it is out of the div.
The text is animated from left to right, so it's not fixed.
It's pretty hard to explain, so i made a image to make you understand better:
Basically everything else except the div and the box should have a higher z-index to obtain this effect, but that's impossible because it would cover everything .
Any idea, possibly using CSS and JS or JQuery?
Share Improve this question asked Jul 22, 2018 at 16:40 Kenneth CaselliKenneth Caselli 611 silver badge5 bronze badges 3-
1
css :
div{overflow:hidden}
? Please provide a minimal reproducible example – charlietfl Commented Jul 22, 2018 at 16:42 - 2 Thanks a lot, this solved my problem! Sorry if it was kind of a silly question – Kenneth Caselli Commented Jul 22, 2018 at 16:43
-
If you want the hidden text to scroll, you can use instead
overflow: auto
– duhaime Commented Jul 22, 2018 at 17:09
3 Answers
Reset to default 4overflow: hidden; white-space: nowrap;
will do the job for you. white-space: nowrap
prevents text from wrapping, while overflow: hidden
hides everything that exceeds div's borders.
Snippet
.container {
height: 300px;
width: 300px;
overflow: hidden;
border: 1px solid black;
white-space: nowrap;
}
<div class="container">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea modo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
Just make the text not wrap, and give the box overflow: hidden
.box {
max-width: 80px;
white-space: nowrap;
overflow: hidden;
background: #efefef;
}
<div class='box'>
<p>Wow look at this text it goes out of the box</p>
</div>
The CSS
property overflow: hidden;
will cause everything which is outside the surface area of the element not to be rendered.
div {
width: 100px;
height: 20px;
background-color: blue;
overflow: hidden;
}
<div> text will go outside this div</div>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745156408a4614147.html
评论列表(0条)