April 7, 2012

How to detect whether css floated items overflows to the next line?

Question by Vlad

When you use float:left or float:right, how do you know when a line has overflown to the next line? For example, I would like a collection of items to flow from left to right side of the screen at the bottom, but when the line overflows to the next line, just hide it. Is there a way to know at which point the float items overflows into the next line?

Answer by Starx

One way to look at would be to

  • Collect the items as per the float Order
  • Calculate the total width
  • Compare against parent and see if its greater.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!