Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a text visible only when inside a div

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:

My problem

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?

like image 864
Kenneth Caselli Avatar asked Oct 28 '25 14:10

Kenneth Caselli


2 Answers

overflow: 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 commodo 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>
like image 58
Andrzej Ziółek Avatar answered Oct 31 '25 04:10

Andrzej Ziółek


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>
like image 27
duhaime Avatar answered Oct 31 '25 03:10

duhaime



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!