Support » Fixing WordPress » floated divs are not contained inside post div container

  • I made 2 floated div’s inside a page. One is floated left the other floated right.

    The problem is the divs no longer exist INSIDE the content div where they should be. So my background color of white which is defined in my post text div css is not as it should be because the content is technically not inside the div because it’s floated.

    In other words the floated divs are no longer inside the post div so there is no white background behind my content. Other pages with no floated divs have the white bg color because they exist inside the div.

    Any ideas how I can fix this?


Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Andrew Nevins


    Can you use overflow: hidden; to the white background element?

    That worked but my container is now like 50px wide and floated all the way to the right.

    Was I supposed to contain the floated divs on the page inside another div?

    I hope not because that means I have to go back to every page and add the wrapper div.


    So something like:



    I just don’t know the trick to make this work.


    Moderator Andrew Nevins


    Check if the page has valid markup first

    @isonychia — Not sure I’m understanding the problem, but why can’t you just apply the white background to the floated elements?

    If you can post a link to your site, it will be much easier for people to offer specific help.

    This is the problem I’m having:

    I will try the overflow but I thought I tried that and it didn’t work.

    Here’s the page:

    I tried overflow hidden and it didn’t work.

    If I do this it works but I’m not sure thats right.


    All I want is to be able to do is float one div left, then float one right next to it, then under those two float another div left WHILE keeping all the content inside the .post-text div

    I never ran into this problem before in wp but I never created floated divs inside the content area.

    It just seems wrong to modify the content div(post-text) which is why I figured I should probably have wrapped those 3 divs inside a wrapper div inside the content div. Hope that made sense.

    What I should have done is stuck to tables, but I didn’t want to use tables because I constantly read I shouldn’t but then I have to float stuff and then I run into problems. Sometimes this web stuff is so complicated just to do simple things it’s really annoying. So many rules/problems just to get 2 boxes lined up next to each other.


    I currently left the page I posted with the float fix, so thats why it looks like it’s fixed.


    I removed the float and tried this, see below. (this may be an old school hack)I would be open to a better option if one exists.

    CSS Container and float DIV

    A common problem with the floating div element is that the floats’ container does not stretch up to accomodate the float. If you set a background image to the container div, you will notice that the float div appears outside of container.

    The solution is to add an extra div element with clear: both after the floating elements. The element with this property doesn’t allow other elements floating upon it and so it will stretch the container to suit the floating div.


Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘floated divs are not contained inside post div container’ is closed to new replies.