CSS setting 4 boxes in 2 rows












0















I've been trying to put 4 boxes together in CSS, 2 in one row and 2 below the first one like this: result



but i can't manage to do it correctly. So far i have this:
before



Parts of my code:






.div {

display:inline-block;
box-sizing: border-box;
border-width:25%;
bottom: 100;
right: 100;

}

#one {
float:right;
border-style: solid;
border-width:5px;
border-color: blue;
box-sizing: border-box;
width: 200px;
height: 130px;
margin:5px;
padding:5px;
}

#two {
float:right;
border-style: solid;
border-color: green;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}

#three {
float:left;
border-style: solid;
border-color: orange;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 150px;
margin:5px;
padding:5px;
}

#four {
float:left;
border-style: solid;
border-color: yellow;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}

p {
padding:5px;
margin:5px;
border-width:25%;
}
p {
margin:10px;
border-width:25%;
}

<div id="one">
</div>
<div id="two">
</div>
<div id="three">
</div>
<div id="four">
</div>





if i put position:fixed so that it won't move every box overlaps the others. How can i make them all aligned like the first image? i want the 2 boxes to be next to each other and the other two at the bottom.
What am i doing wrong with the position of the boxes and the margins? I know the whole box model with padding and margin but i can't understand exactly how i'm supposed to place the boxes correctly.
Thank you in advance.










share|improve this question























  • I have to do this only with CSS, i can't change the html file. Can i do it wih just CSS?

    – KatyK
    Nov 26 '18 at 18:47
















0















I've been trying to put 4 boxes together in CSS, 2 in one row and 2 below the first one like this: result



but i can't manage to do it correctly. So far i have this:
before



Parts of my code:






.div {

display:inline-block;
box-sizing: border-box;
border-width:25%;
bottom: 100;
right: 100;

}

#one {
float:right;
border-style: solid;
border-width:5px;
border-color: blue;
box-sizing: border-box;
width: 200px;
height: 130px;
margin:5px;
padding:5px;
}

#two {
float:right;
border-style: solid;
border-color: green;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}

#three {
float:left;
border-style: solid;
border-color: orange;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 150px;
margin:5px;
padding:5px;
}

#four {
float:left;
border-style: solid;
border-color: yellow;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}

p {
padding:5px;
margin:5px;
border-width:25%;
}
p {
margin:10px;
border-width:25%;
}

<div id="one">
</div>
<div id="two">
</div>
<div id="three">
</div>
<div id="four">
</div>





if i put position:fixed so that it won't move every box overlaps the others. How can i make them all aligned like the first image? i want the 2 boxes to be next to each other and the other two at the bottom.
What am i doing wrong with the position of the boxes and the margins? I know the whole box model with padding and margin but i can't understand exactly how i'm supposed to place the boxes correctly.
Thank you in advance.










share|improve this question























  • I have to do this only with CSS, i can't change the html file. Can i do it wih just CSS?

    – KatyK
    Nov 26 '18 at 18:47














0












0








0








I've been trying to put 4 boxes together in CSS, 2 in one row and 2 below the first one like this: result



but i can't manage to do it correctly. So far i have this:
before



Parts of my code:






.div {

display:inline-block;
box-sizing: border-box;
border-width:25%;
bottom: 100;
right: 100;

}

#one {
float:right;
border-style: solid;
border-width:5px;
border-color: blue;
box-sizing: border-box;
width: 200px;
height: 130px;
margin:5px;
padding:5px;
}

#two {
float:right;
border-style: solid;
border-color: green;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}

#three {
float:left;
border-style: solid;
border-color: orange;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 150px;
margin:5px;
padding:5px;
}

#four {
float:left;
border-style: solid;
border-color: yellow;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}

p {
padding:5px;
margin:5px;
border-width:25%;
}
p {
margin:10px;
border-width:25%;
}

<div id="one">
</div>
<div id="two">
</div>
<div id="three">
</div>
<div id="four">
</div>





if i put position:fixed so that it won't move every box overlaps the others. How can i make them all aligned like the first image? i want the 2 boxes to be next to each other and the other two at the bottom.
What am i doing wrong with the position of the boxes and the margins? I know the whole box model with padding and margin but i can't understand exactly how i'm supposed to place the boxes correctly.
Thank you in advance.










share|improve this question














I've been trying to put 4 boxes together in CSS, 2 in one row and 2 below the first one like this: result



but i can't manage to do it correctly. So far i have this:
before



Parts of my code:






.div {

display:inline-block;
box-sizing: border-box;
border-width:25%;
bottom: 100;
right: 100;

}

#one {
float:right;
border-style: solid;
border-width:5px;
border-color: blue;
box-sizing: border-box;
width: 200px;
height: 130px;
margin:5px;
padding:5px;
}

#two {
float:right;
border-style: solid;
border-color: green;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}

#three {
float:left;
border-style: solid;
border-color: orange;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 150px;
margin:5px;
padding:5px;
}

#four {
float:left;
border-style: solid;
border-color: yellow;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}

p {
padding:5px;
margin:5px;
border-width:25%;
}
p {
margin:10px;
border-width:25%;
}

<div id="one">
</div>
<div id="two">
</div>
<div id="three">
</div>
<div id="four">
</div>





if i put position:fixed so that it won't move every box overlaps the others. How can i make them all aligned like the first image? i want the 2 boxes to be next to each other and the other two at the bottom.
What am i doing wrong with the position of the boxes and the margins? I know the whole box model with padding and margin but i can't understand exactly how i'm supposed to place the boxes correctly.
Thank you in advance.






.div {

display:inline-block;
box-sizing: border-box;
border-width:25%;
bottom: 100;
right: 100;

}

#one {
float:right;
border-style: solid;
border-width:5px;
border-color: blue;
box-sizing: border-box;
width: 200px;
height: 130px;
margin:5px;
padding:5px;
}

#two {
float:right;
border-style: solid;
border-color: green;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}

#three {
float:left;
border-style: solid;
border-color: orange;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 150px;
margin:5px;
padding:5px;
}

#four {
float:left;
border-style: solid;
border-color: yellow;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}

p {
padding:5px;
margin:5px;
border-width:25%;
}
p {
margin:10px;
border-width:25%;
}

<div id="one">
</div>
<div id="two">
</div>
<div id="three">
</div>
<div id="four">
</div>





.div {

display:inline-block;
box-sizing: border-box;
border-width:25%;
bottom: 100;
right: 100;

}

#one {
float:right;
border-style: solid;
border-width:5px;
border-color: blue;
box-sizing: border-box;
width: 200px;
height: 130px;
margin:5px;
padding:5px;
}

#two {
float:right;
border-style: solid;
border-color: green;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}

#three {
float:left;
border-style: solid;
border-color: orange;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 150px;
margin:5px;
padding:5px;
}

#four {
float:left;
border-style: solid;
border-color: yellow;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}

p {
padding:5px;
margin:5px;
border-width:25%;
}
p {
margin:10px;
border-width:25%;
}

<div id="one">
</div>
<div id="two">
</div>
<div id="three">
</div>
<div id="four">
</div>






html css






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 1:34









KatyKKatyK

23




23













  • I have to do this only with CSS, i can't change the html file. Can i do it wih just CSS?

    – KatyK
    Nov 26 '18 at 18:47



















  • I have to do this only with CSS, i can't change the html file. Can i do it wih just CSS?

    – KatyK
    Nov 26 '18 at 18:47

















I have to do this only with CSS, i can't change the html file. Can i do it wih just CSS?

– KatyK
Nov 26 '18 at 18:47





I have to do this only with CSS, i can't change the html file. Can i do it wih just CSS?

– KatyK
Nov 26 '18 at 18:47












4 Answers
4






active

oldest

votes


















1














There are a few ways to approach this, I would say the easiest would be using CSS Grid. CSS Grid is a two-dimensional layout system for the web, allowing for you to have better control over rows and columns.



You could accomplish this by using CSS Flexbox, but it would take a little more configuring and may not look as "eloquent".



Here are some sources for CSS Grid:



Mozilla Docs



CSS Reference



I modified your code by wrapping your html with a container and adding grid to it, the example is below:



CSS



.container {
display: grid;
grid-gap: 5rem;
grid-template-columns: 200px 200px;
}

#one {
border-style: solid;
border-width:5px;
border-color: blue;
box-sizing: border-box;
width: 200px;
height: 130px;
margin:5px;
padding:5px;
}

#two {
border-style: solid;
border-color: green;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}

#three {
border-style: solid;
border-color: orange;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 150px;
margin:5px;
padding:5px;
}

#four {
border-style: solid;
border-color: yellow;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin:5px;
padding:5px;
}


HTML



<div class="container">
<div id="one">
</div>
<div id="two">
</div>
<div id="three">
</div>
<div id="four">
</div>
</div>





share|improve this answer


























  • This. Unless there is a compelling reason not to (such as some backwards compatibility), CSS Grid should be your default for layout. It makes most challenges, such as this, so much easier to deal with.

    – karolus
    Nov 26 '18 at 2:13



















0














What I roughly did :



HTML :



  <div id="one">
</div>

<div id="two">
</div>

<div id="three">
</div>

<div id="four">
</div>


CSS:



#one {
float:left;
border-style: solid;
border-width:5px;
border-color: orange;
box-sizing: border-box;
width: 200px;
height: 130px;
margin:5px;
padding:5px;
}

#four {
float:left;
border-style: solid;
border-color: yellow;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin-top:50px;
padding:5px;
}

#two {
float:left;
border-style: solid;
border-color: green;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 130px;
margin-left:100px;
margin-top:7px;
padding:5px;
}

#three {
float:right;
border-style: solid;
border-color: blue;
border-width:5px;
box-sizing: border-box;
width: 200px;
height: 110px;
margin-top:50px;
margin-right:90px;
padding:5px;
}

p {
padding:5px;
margin:5px;
border-width:25%;
}
p {
margin:10px;
border-width:25%;
}





share|improve this answer































    0














    When you have the divs set as inline blocks they will render in the order of the HTML, starting from the top left of their container. The rules are applied as though the browser is reading text: left to right. You can get something closer to what you are trying to achieve by reordering the divs like this:



    <div id="three">
    </div>
    <div id="two">
    </div>
    <div id="one">
    </div>
    <div id="four">
    </div>


    In a larger container this will show all the boxes on a single line, but on a smaller screen (or inside a smaller container) they will look like this:



    Orange box (left float)..........Green box (right float)



    Yellow box (left float)..........Blue box (right float)



    There are a lot of different approaches to make this layout work for you:




    1. You can use the display: table property and treat the divs like a two-row two-column table

    2. wrap the two divs on top in another div container (display: block

    3. Use the code listed above with re-ordered divs (using your existing css)


    I hope this helps. If I had a more concrete understanding of what you were trying to accomplish I could give you a more directed answer.






    share|improve this answer































      0














      A couple of changes to your CSS/HTML code should be all it takes.

      Add the following lines to the corresponding CSS ID's:




      #one {
      grid-area: orange 1/1/2/2;
      ...

      #two {
      grid-area: green 1/2/2/3;
      ...

      #three {
      grid-area: yellow 2/1/3/2;
      ...

      #four {
      grid-area: blue 2/2/3/3;
      ...



      The grid-area element will "lock in" or assign a specific placement for each box. The area(s) count the lines of your boxes top/left/bottom/right based on the desired image. Note: your image shows 4 equally sized boxes, but your CSS code shows 2 square and 2 rectangular boxes. This code will work well with 4 squares, but you might have some editing for different shapes.



      Next:
      Add a CSS class for a container and slightly adjust the div class you currently have:




      .grid-container {
      display: grid;
      grid-template areas: 'orange green yellow blue';
      grid-gap: 0;
      margin-left: auto;
      margin-right: auto;
      padding: 0;
      max-width: 1150px;
      position: center; }

      .grid-container > div {
      padding 0;
      ...



      Then:
      Add the container (or wrapper) div tag to your HTML code:




          <div class="grid-container">
      <div id="one"> </div>
      ...
      </div>



      That should produce the desired results. Hope it helps!






      share|improve this answer























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473730%2fcss-setting-4-boxes-in-2-rows%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        There are a few ways to approach this, I would say the easiest would be using CSS Grid. CSS Grid is a two-dimensional layout system for the web, allowing for you to have better control over rows and columns.



        You could accomplish this by using CSS Flexbox, but it would take a little more configuring and may not look as "eloquent".



        Here are some sources for CSS Grid:



        Mozilla Docs



        CSS Reference



        I modified your code by wrapping your html with a container and adding grid to it, the example is below:



        CSS



        .container {
        display: grid;
        grid-gap: 5rem;
        grid-template-columns: 200px 200px;
        }

        #one {
        border-style: solid;
        border-width:5px;
        border-color: blue;
        box-sizing: border-box;
        width: 200px;
        height: 130px;
        margin:5px;
        padding:5px;
        }

        #two {
        border-style: solid;
        border-color: green;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 110px;
        margin:5px;
        padding:5px;
        }

        #three {
        border-style: solid;
        border-color: orange;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 150px;
        margin:5px;
        padding:5px;
        }

        #four {
        border-style: solid;
        border-color: yellow;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 110px;
        margin:5px;
        padding:5px;
        }


        HTML



        <div class="container">
        <div id="one">
        </div>
        <div id="two">
        </div>
        <div id="three">
        </div>
        <div id="four">
        </div>
        </div>





        share|improve this answer


























        • This. Unless there is a compelling reason not to (such as some backwards compatibility), CSS Grid should be your default for layout. It makes most challenges, such as this, so much easier to deal with.

          – karolus
          Nov 26 '18 at 2:13
















        1














        There are a few ways to approach this, I would say the easiest would be using CSS Grid. CSS Grid is a two-dimensional layout system for the web, allowing for you to have better control over rows and columns.



        You could accomplish this by using CSS Flexbox, but it would take a little more configuring and may not look as "eloquent".



        Here are some sources for CSS Grid:



        Mozilla Docs



        CSS Reference



        I modified your code by wrapping your html with a container and adding grid to it, the example is below:



        CSS



        .container {
        display: grid;
        grid-gap: 5rem;
        grid-template-columns: 200px 200px;
        }

        #one {
        border-style: solid;
        border-width:5px;
        border-color: blue;
        box-sizing: border-box;
        width: 200px;
        height: 130px;
        margin:5px;
        padding:5px;
        }

        #two {
        border-style: solid;
        border-color: green;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 110px;
        margin:5px;
        padding:5px;
        }

        #three {
        border-style: solid;
        border-color: orange;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 150px;
        margin:5px;
        padding:5px;
        }

        #four {
        border-style: solid;
        border-color: yellow;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 110px;
        margin:5px;
        padding:5px;
        }


        HTML



        <div class="container">
        <div id="one">
        </div>
        <div id="two">
        </div>
        <div id="three">
        </div>
        <div id="four">
        </div>
        </div>





        share|improve this answer


























        • This. Unless there is a compelling reason not to (such as some backwards compatibility), CSS Grid should be your default for layout. It makes most challenges, such as this, so much easier to deal with.

          – karolus
          Nov 26 '18 at 2:13














        1












        1








        1







        There are a few ways to approach this, I would say the easiest would be using CSS Grid. CSS Grid is a two-dimensional layout system for the web, allowing for you to have better control over rows and columns.



        You could accomplish this by using CSS Flexbox, but it would take a little more configuring and may not look as "eloquent".



        Here are some sources for CSS Grid:



        Mozilla Docs



        CSS Reference



        I modified your code by wrapping your html with a container and adding grid to it, the example is below:



        CSS



        .container {
        display: grid;
        grid-gap: 5rem;
        grid-template-columns: 200px 200px;
        }

        #one {
        border-style: solid;
        border-width:5px;
        border-color: blue;
        box-sizing: border-box;
        width: 200px;
        height: 130px;
        margin:5px;
        padding:5px;
        }

        #two {
        border-style: solid;
        border-color: green;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 110px;
        margin:5px;
        padding:5px;
        }

        #three {
        border-style: solid;
        border-color: orange;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 150px;
        margin:5px;
        padding:5px;
        }

        #four {
        border-style: solid;
        border-color: yellow;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 110px;
        margin:5px;
        padding:5px;
        }


        HTML



        <div class="container">
        <div id="one">
        </div>
        <div id="two">
        </div>
        <div id="three">
        </div>
        <div id="four">
        </div>
        </div>





        share|improve this answer















        There are a few ways to approach this, I would say the easiest would be using CSS Grid. CSS Grid is a two-dimensional layout system for the web, allowing for you to have better control over rows and columns.



        You could accomplish this by using CSS Flexbox, but it would take a little more configuring and may not look as "eloquent".



        Here are some sources for CSS Grid:



        Mozilla Docs



        CSS Reference



        I modified your code by wrapping your html with a container and adding grid to it, the example is below:



        CSS



        .container {
        display: grid;
        grid-gap: 5rem;
        grid-template-columns: 200px 200px;
        }

        #one {
        border-style: solid;
        border-width:5px;
        border-color: blue;
        box-sizing: border-box;
        width: 200px;
        height: 130px;
        margin:5px;
        padding:5px;
        }

        #two {
        border-style: solid;
        border-color: green;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 110px;
        margin:5px;
        padding:5px;
        }

        #three {
        border-style: solid;
        border-color: orange;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 150px;
        margin:5px;
        padding:5px;
        }

        #four {
        border-style: solid;
        border-color: yellow;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 110px;
        margin:5px;
        padding:5px;
        }


        HTML



        <div class="container">
        <div id="one">
        </div>
        <div id="two">
        </div>
        <div id="three">
        </div>
        <div id="four">
        </div>
        </div>






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 26 '18 at 16:04

























        answered Nov 26 '18 at 2:04









        RobRob

        4625




        4625













        • This. Unless there is a compelling reason not to (such as some backwards compatibility), CSS Grid should be your default for layout. It makes most challenges, such as this, so much easier to deal with.

          – karolus
          Nov 26 '18 at 2:13



















        • This. Unless there is a compelling reason not to (such as some backwards compatibility), CSS Grid should be your default for layout. It makes most challenges, such as this, so much easier to deal with.

          – karolus
          Nov 26 '18 at 2:13

















        This. Unless there is a compelling reason not to (such as some backwards compatibility), CSS Grid should be your default for layout. It makes most challenges, such as this, so much easier to deal with.

        – karolus
        Nov 26 '18 at 2:13





        This. Unless there is a compelling reason not to (such as some backwards compatibility), CSS Grid should be your default for layout. It makes most challenges, such as this, so much easier to deal with.

        – karolus
        Nov 26 '18 at 2:13













        0














        What I roughly did :



        HTML :



          <div id="one">
        </div>

        <div id="two">
        </div>

        <div id="three">
        </div>

        <div id="four">
        </div>


        CSS:



        #one {
        float:left;
        border-style: solid;
        border-width:5px;
        border-color: orange;
        box-sizing: border-box;
        width: 200px;
        height: 130px;
        margin:5px;
        padding:5px;
        }

        #four {
        float:left;
        border-style: solid;
        border-color: yellow;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 110px;
        margin-top:50px;
        padding:5px;
        }

        #two {
        float:left;
        border-style: solid;
        border-color: green;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 130px;
        margin-left:100px;
        margin-top:7px;
        padding:5px;
        }

        #three {
        float:right;
        border-style: solid;
        border-color: blue;
        border-width:5px;
        box-sizing: border-box;
        width: 200px;
        height: 110px;
        margin-top:50px;
        margin-right:90px;
        padding:5px;
        }

        p {
        padding:5px;
        margin:5px;
        border-width:25%;
        }
        p {
        margin:10px;
        border-width:25%;
        }





        share|improve this answer




























          0














          What I roughly did :



          HTML :



            <div id="one">
          </div>

          <div id="two">
          </div>

          <div id="three">
          </div>

          <div id="four">
          </div>


          CSS:



          #one {
          float:left;
          border-style: solid;
          border-width:5px;
          border-color: orange;
          box-sizing: border-box;
          width: 200px;
          height: 130px;
          margin:5px;
          padding:5px;
          }

          #four {
          float:left;
          border-style: solid;
          border-color: yellow;
          border-width:5px;
          box-sizing: border-box;
          width: 200px;
          height: 110px;
          margin-top:50px;
          padding:5px;
          }

          #two {
          float:left;
          border-style: solid;
          border-color: green;
          border-width:5px;
          box-sizing: border-box;
          width: 200px;
          height: 130px;
          margin-left:100px;
          margin-top:7px;
          padding:5px;
          }

          #three {
          float:right;
          border-style: solid;
          border-color: blue;
          border-width:5px;
          box-sizing: border-box;
          width: 200px;
          height: 110px;
          margin-top:50px;
          margin-right:90px;
          padding:5px;
          }

          p {
          padding:5px;
          margin:5px;
          border-width:25%;
          }
          p {
          margin:10px;
          border-width:25%;
          }





          share|improve this answer


























            0












            0








            0







            What I roughly did :



            HTML :



              <div id="one">
            </div>

            <div id="two">
            </div>

            <div id="three">
            </div>

            <div id="four">
            </div>


            CSS:



            #one {
            float:left;
            border-style: solid;
            border-width:5px;
            border-color: orange;
            box-sizing: border-box;
            width: 200px;
            height: 130px;
            margin:5px;
            padding:5px;
            }

            #four {
            float:left;
            border-style: solid;
            border-color: yellow;
            border-width:5px;
            box-sizing: border-box;
            width: 200px;
            height: 110px;
            margin-top:50px;
            padding:5px;
            }

            #two {
            float:left;
            border-style: solid;
            border-color: green;
            border-width:5px;
            box-sizing: border-box;
            width: 200px;
            height: 130px;
            margin-left:100px;
            margin-top:7px;
            padding:5px;
            }

            #three {
            float:right;
            border-style: solid;
            border-color: blue;
            border-width:5px;
            box-sizing: border-box;
            width: 200px;
            height: 110px;
            margin-top:50px;
            margin-right:90px;
            padding:5px;
            }

            p {
            padding:5px;
            margin:5px;
            border-width:25%;
            }
            p {
            margin:10px;
            border-width:25%;
            }





            share|improve this answer













            What I roughly did :



            HTML :



              <div id="one">
            </div>

            <div id="two">
            </div>

            <div id="three">
            </div>

            <div id="four">
            </div>


            CSS:



            #one {
            float:left;
            border-style: solid;
            border-width:5px;
            border-color: orange;
            box-sizing: border-box;
            width: 200px;
            height: 130px;
            margin:5px;
            padding:5px;
            }

            #four {
            float:left;
            border-style: solid;
            border-color: yellow;
            border-width:5px;
            box-sizing: border-box;
            width: 200px;
            height: 110px;
            margin-top:50px;
            padding:5px;
            }

            #two {
            float:left;
            border-style: solid;
            border-color: green;
            border-width:5px;
            box-sizing: border-box;
            width: 200px;
            height: 130px;
            margin-left:100px;
            margin-top:7px;
            padding:5px;
            }

            #three {
            float:right;
            border-style: solid;
            border-color: blue;
            border-width:5px;
            box-sizing: border-box;
            width: 200px;
            height: 110px;
            margin-top:50px;
            margin-right:90px;
            padding:5px;
            }

            p {
            padding:5px;
            margin:5px;
            border-width:25%;
            }
            p {
            margin:10px;
            border-width:25%;
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 26 '18 at 2:10









            WolfiebaeWolfiebae

            2712




            2712























                0














                When you have the divs set as inline blocks they will render in the order of the HTML, starting from the top left of their container. The rules are applied as though the browser is reading text: left to right. You can get something closer to what you are trying to achieve by reordering the divs like this:



                <div id="three">
                </div>
                <div id="two">
                </div>
                <div id="one">
                </div>
                <div id="four">
                </div>


                In a larger container this will show all the boxes on a single line, but on a smaller screen (or inside a smaller container) they will look like this:



                Orange box (left float)..........Green box (right float)



                Yellow box (left float)..........Blue box (right float)



                There are a lot of different approaches to make this layout work for you:




                1. You can use the display: table property and treat the divs like a two-row two-column table

                2. wrap the two divs on top in another div container (display: block

                3. Use the code listed above with re-ordered divs (using your existing css)


                I hope this helps. If I had a more concrete understanding of what you were trying to accomplish I could give you a more directed answer.






                share|improve this answer




























                  0














                  When you have the divs set as inline blocks they will render in the order of the HTML, starting from the top left of their container. The rules are applied as though the browser is reading text: left to right. You can get something closer to what you are trying to achieve by reordering the divs like this:



                  <div id="three">
                  </div>
                  <div id="two">
                  </div>
                  <div id="one">
                  </div>
                  <div id="four">
                  </div>


                  In a larger container this will show all the boxes on a single line, but on a smaller screen (or inside a smaller container) they will look like this:



                  Orange box (left float)..........Green box (right float)



                  Yellow box (left float)..........Blue box (right float)



                  There are a lot of different approaches to make this layout work for you:




                  1. You can use the display: table property and treat the divs like a two-row two-column table

                  2. wrap the two divs on top in another div container (display: block

                  3. Use the code listed above with re-ordered divs (using your existing css)


                  I hope this helps. If I had a more concrete understanding of what you were trying to accomplish I could give you a more directed answer.






                  share|improve this answer


























                    0












                    0








                    0







                    When you have the divs set as inline blocks they will render in the order of the HTML, starting from the top left of their container. The rules are applied as though the browser is reading text: left to right. You can get something closer to what you are trying to achieve by reordering the divs like this:



                    <div id="three">
                    </div>
                    <div id="two">
                    </div>
                    <div id="one">
                    </div>
                    <div id="four">
                    </div>


                    In a larger container this will show all the boxes on a single line, but on a smaller screen (or inside a smaller container) they will look like this:



                    Orange box (left float)..........Green box (right float)



                    Yellow box (left float)..........Blue box (right float)



                    There are a lot of different approaches to make this layout work for you:




                    1. You can use the display: table property and treat the divs like a two-row two-column table

                    2. wrap the two divs on top in another div container (display: block

                    3. Use the code listed above with re-ordered divs (using your existing css)


                    I hope this helps. If I had a more concrete understanding of what you were trying to accomplish I could give you a more directed answer.






                    share|improve this answer













                    When you have the divs set as inline blocks they will render in the order of the HTML, starting from the top left of their container. The rules are applied as though the browser is reading text: left to right. You can get something closer to what you are trying to achieve by reordering the divs like this:



                    <div id="three">
                    </div>
                    <div id="two">
                    </div>
                    <div id="one">
                    </div>
                    <div id="four">
                    </div>


                    In a larger container this will show all the boxes on a single line, but on a smaller screen (or inside a smaller container) they will look like this:



                    Orange box (left float)..........Green box (right float)



                    Yellow box (left float)..........Blue box (right float)



                    There are a lot of different approaches to make this layout work for you:




                    1. You can use the display: table property and treat the divs like a two-row two-column table

                    2. wrap the two divs on top in another div container (display: block

                    3. Use the code listed above with re-ordered divs (using your existing css)


                    I hope this helps. If I had a more concrete understanding of what you were trying to accomplish I could give you a more directed answer.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 26 '18 at 2:12









                    tshimkustshimkus

                    566419




                    566419























                        0














                        A couple of changes to your CSS/HTML code should be all it takes.

                        Add the following lines to the corresponding CSS ID's:




                        #one {
                        grid-area: orange 1/1/2/2;
                        ...

                        #two {
                        grid-area: green 1/2/2/3;
                        ...

                        #three {
                        grid-area: yellow 2/1/3/2;
                        ...

                        #four {
                        grid-area: blue 2/2/3/3;
                        ...



                        The grid-area element will "lock in" or assign a specific placement for each box. The area(s) count the lines of your boxes top/left/bottom/right based on the desired image. Note: your image shows 4 equally sized boxes, but your CSS code shows 2 square and 2 rectangular boxes. This code will work well with 4 squares, but you might have some editing for different shapes.



                        Next:
                        Add a CSS class for a container and slightly adjust the div class you currently have:




                        .grid-container {
                        display: grid;
                        grid-template areas: 'orange green yellow blue';
                        grid-gap: 0;
                        margin-left: auto;
                        margin-right: auto;
                        padding: 0;
                        max-width: 1150px;
                        position: center; }

                        .grid-container > div {
                        padding 0;
                        ...



                        Then:
                        Add the container (or wrapper) div tag to your HTML code:




                            <div class="grid-container">
                        <div id="one"> </div>
                        ...
                        </div>



                        That should produce the desired results. Hope it helps!






                        share|improve this answer




























                          0














                          A couple of changes to your CSS/HTML code should be all it takes.

                          Add the following lines to the corresponding CSS ID's:




                          #one {
                          grid-area: orange 1/1/2/2;
                          ...

                          #two {
                          grid-area: green 1/2/2/3;
                          ...

                          #three {
                          grid-area: yellow 2/1/3/2;
                          ...

                          #four {
                          grid-area: blue 2/2/3/3;
                          ...



                          The grid-area element will "lock in" or assign a specific placement for each box. The area(s) count the lines of your boxes top/left/bottom/right based on the desired image. Note: your image shows 4 equally sized boxes, but your CSS code shows 2 square and 2 rectangular boxes. This code will work well with 4 squares, but you might have some editing for different shapes.



                          Next:
                          Add a CSS class for a container and slightly adjust the div class you currently have:




                          .grid-container {
                          display: grid;
                          grid-template areas: 'orange green yellow blue';
                          grid-gap: 0;
                          margin-left: auto;
                          margin-right: auto;
                          padding: 0;
                          max-width: 1150px;
                          position: center; }

                          .grid-container > div {
                          padding 0;
                          ...



                          Then:
                          Add the container (or wrapper) div tag to your HTML code:




                              <div class="grid-container">
                          <div id="one"> </div>
                          ...
                          </div>



                          That should produce the desired results. Hope it helps!






                          share|improve this answer


























                            0












                            0








                            0







                            A couple of changes to your CSS/HTML code should be all it takes.

                            Add the following lines to the corresponding CSS ID's:




                            #one {
                            grid-area: orange 1/1/2/2;
                            ...

                            #two {
                            grid-area: green 1/2/2/3;
                            ...

                            #three {
                            grid-area: yellow 2/1/3/2;
                            ...

                            #four {
                            grid-area: blue 2/2/3/3;
                            ...



                            The grid-area element will "lock in" or assign a specific placement for each box. The area(s) count the lines of your boxes top/left/bottom/right based on the desired image. Note: your image shows 4 equally sized boxes, but your CSS code shows 2 square and 2 rectangular boxes. This code will work well with 4 squares, but you might have some editing for different shapes.



                            Next:
                            Add a CSS class for a container and slightly adjust the div class you currently have:




                            .grid-container {
                            display: grid;
                            grid-template areas: 'orange green yellow blue';
                            grid-gap: 0;
                            margin-left: auto;
                            margin-right: auto;
                            padding: 0;
                            max-width: 1150px;
                            position: center; }

                            .grid-container > div {
                            padding 0;
                            ...



                            Then:
                            Add the container (or wrapper) div tag to your HTML code:




                                <div class="grid-container">
                            <div id="one"> </div>
                            ...
                            </div>



                            That should produce the desired results. Hope it helps!






                            share|improve this answer













                            A couple of changes to your CSS/HTML code should be all it takes.

                            Add the following lines to the corresponding CSS ID's:




                            #one {
                            grid-area: orange 1/1/2/2;
                            ...

                            #two {
                            grid-area: green 1/2/2/3;
                            ...

                            #three {
                            grid-area: yellow 2/1/3/2;
                            ...

                            #four {
                            grid-area: blue 2/2/3/3;
                            ...



                            The grid-area element will "lock in" or assign a specific placement for each box. The area(s) count the lines of your boxes top/left/bottom/right based on the desired image. Note: your image shows 4 equally sized boxes, but your CSS code shows 2 square and 2 rectangular boxes. This code will work well with 4 squares, but you might have some editing for different shapes.



                            Next:
                            Add a CSS class for a container and slightly adjust the div class you currently have:




                            .grid-container {
                            display: grid;
                            grid-template areas: 'orange green yellow blue';
                            grid-gap: 0;
                            margin-left: auto;
                            margin-right: auto;
                            padding: 0;
                            max-width: 1150px;
                            position: center; }

                            .grid-container > div {
                            padding 0;
                            ...



                            Then:
                            Add the container (or wrapper) div tag to your HTML code:




                                <div class="grid-container">
                            <div id="one"> </div>
                            ...
                            </div>



                            That should produce the desired results. Hope it helps!







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 26 '18 at 6:59









                            elbrantelbrant

                            41428




                            41428






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473730%2fcss-setting-4-boxes-in-2-rows%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                                Calculate evaluation metrics using cross_val_predict sklearn

                                Insert data from modal to MySQL (multiple modal on website)