The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Aligning issue with floating divs

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #36154

    I have a question about aligning divs that float left.

    In the image you see the issue that I have.

    The divs have margins right and left 20 px

    But I only want this to have influence on the content that is in it.

    Is there a way to get this done? I really need this because my website is all about strict alignments.


    I can’t access the image.

    But how about changing the margin property to “padding”?


    Does the container have a background image? There is an easy way around it if it doesn’t.


    Here I have the issue in html/css : LINK I know there ways arround but they cost more energy to apply. My solutions is a smarter one, just make the parent ignore the margin of the childs! So no individual classes per block is needed.

    Hope this makes it a bit clearer ;)





    Hope this works for you

    .block {
    background-color: #CCCCCC;
    float: left;
    height: 170px;
    margin-left: 20px;
    margin-top: 20px;
    width: 170px;


    I would highly recommend using the solution I have taken the time to outline for you here:


    @andy_unleash Put simply: it’s not what they were meant to be used for. We have used them as CSS offers nothing better, although that looks set to change. Evidence to my opinion is the number of issues with float based layouts. The biggest culprit being the need to use a clearfix hack. Most of the time, inline-block will suffice.


    It has been a while I looked over here! Thanks for the help ;)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.