How to fix floating elements within a div that are floating outside of the div with CSS?

Spread the love

Sometimes, we want to fix floating elements within a div that are floating outside of the div with CSS.

In this article, we’ll look at how to fix floating elements within a div that are floating outside of the div with CSS.

How to fix floating elements within a div that are floating outside of the div with CSS?

To fix floating elements within a div that are floating outside of the div with CSS, we hide the overflow in the parent.

For instance, we write

<div class="parent">
  <img class="floated_child" src="..." />
  <span class="clear"></span>
</div>

to add a div with some content.

Then we write

#parent {
  overflow: hidden;
}

to hide the overflow on the outer div.

Conclusion

To fix floating elements within a div that are floating outside of the div with CSS, we hide the overflow in the parent.

Leave a Reply

Your email address will not be published. Required fields are marked *