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

Home Forums CSS About evenly divs inside another div

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


    I want to get evenly divs inside another div. I have this code:



    .container {
    background: red;
    width: 500px;
    height: 200px;
    .contained {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    width: 45%;
    margin: 2.5%;
    float: left;
    padding: 10px;
    .one {
    background: blue;
    background: green;

    It seems it works ok, but my question is: in that way I have now, when I resize the side margins of the contained divs, I have to change also the width of those divs. For me this is a bit stupid, because I think changing the margins should be enough, because after changing the margin, the divs should adapt its width automatically (that’s my idea).

    Do you understand me? Am I doing something wrong to get those evenly divs or my approach is correct?



    Try this:

    Thing is…you have three ‘gaps’ with two divs (left, middle & right).So whatever remainder you have left after totalling the width of the divs has to be divided accordingly.

    So we remove the left margin from the right div and there you go.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘CSS’ is closed to new topics and replies.