Detecting elements inside <p> that is floating

They have: 426 posts

Joined: Feb 2005

Hi all,

I am loading some javascript on a page which inserts an image after each . Trouble is if I have a div element or any other element inside the that is floating to either left or right, the image is does not fit under the correctly.

I need a way of detecting whether there is another element inside the that is floating so I can stop inserting the image altogether and move onto the next ?

any help or advice appreciated.

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

Are you sure you need JS for this? If you add this to your CSS:

img {
    display:block;
    clear:both;
}

Does it fix the problem? It might mess up other images on the page though Sad. If you can add a class name to the images included by the JS, you can change the CSS to apply only to those images.

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

Hard to know the problem exactly without a link but, a lot of the time, if you have a bunch of elements are floating inside another element - commonly a DIV - if you set the containing element to overflow:hidden; then it will display correctly, and not hide the containing elements.

<style type="text/css">
#gallery-container {
overflow:hidden;
}
.gallery-item {
float:left;
width:100px;
height:100px;
margin:10px;
}
</style>

<div id="gallery-container">
<div class="gallery-item"><img src="image.gif" width="100" height="100" alt="" title="" /></div>
<div class="gallery-item"><img src="image.gif" width="100" height="100" alt="" title="" /></div>
<div class="gallery-item"><img src="image.gif" width="100" height="100" alt="" title="" /></div>
<div class="gallery-item"><img src="image.gif" width="100" height="100" alt="" title="" /></div>
</div>

There are of course, other ways to do the above, but it was the best example I could think of off the top of my head.

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

er... ok, the code didn't come out as I posted it..

They have: 1 posts

Joined: Feb 2012

WHAT IS THE MEANING OF DETECTING ELEMENT IN MARINE AUTOMINATION?

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.