How to place div side by side












200















I have a main wrapper div that is set 100% width. Inside that i would like to have two divs, one that is fixed width and the other that fills the rest of the space. How do i float the second div to fill the rest of the space. Thanks for any help.










share|improve this question























  • Next time also place your example code please so the question becomes clearer to the developers here..

    – Rob
    Apr 14 '10 at 13:35











  • is position:absolute an option? you can set the position to the sides of the container, and the div will take the new size.

    – AlexanderMP
    Apr 14 '10 at 13:35
















200















I have a main wrapper div that is set 100% width. Inside that i would like to have two divs, one that is fixed width and the other that fills the rest of the space. How do i float the second div to fill the rest of the space. Thanks for any help.










share|improve this question























  • Next time also place your example code please so the question becomes clearer to the developers here..

    – Rob
    Apr 14 '10 at 13:35











  • is position:absolute an option? you can set the position to the sides of the container, and the div will take the new size.

    – AlexanderMP
    Apr 14 '10 at 13:35














200












200








200


58






I have a main wrapper div that is set 100% width. Inside that i would like to have two divs, one that is fixed width and the other that fills the rest of the space. How do i float the second div to fill the rest of the space. Thanks for any help.










share|improve this question














I have a main wrapper div that is set 100% width. Inside that i would like to have two divs, one that is fixed width and the other that fills the rest of the space. How do i float the second div to fill the rest of the space. Thanks for any help.







html css






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 14 '10 at 13:28









marktmarkt

1,003284




1,003284













  • Next time also place your example code please so the question becomes clearer to the developers here..

    – Rob
    Apr 14 '10 at 13:35











  • is position:absolute an option? you can set the position to the sides of the container, and the div will take the new size.

    – AlexanderMP
    Apr 14 '10 at 13:35



















  • Next time also place your example code please so the question becomes clearer to the developers here..

    – Rob
    Apr 14 '10 at 13:35











  • is position:absolute an option? you can set the position to the sides of the container, and the div will take the new size.

    – AlexanderMP
    Apr 14 '10 at 13:35

















Next time also place your example code please so the question becomes clearer to the developers here..

– Rob
Apr 14 '10 at 13:35





Next time also place your example code please so the question becomes clearer to the developers here..

– Rob
Apr 14 '10 at 13:35













is position:absolute an option? you can set the position to the sides of the container, and the div will take the new size.

– AlexanderMP
Apr 14 '10 at 13:35





is position:absolute an option? you can set the position to the sides of the container, and the div will take the new size.

– AlexanderMP
Apr 14 '10 at 13:35












7 Answers
7






active

oldest

votes


















302














There are many ways to do what you're asking for:





  1. Using CSS float property:



    <div style="width: 100%; overflow: hidden;">
    <div style="width: 600px; float: left;"> Left </div>
    <div style="margin-left: 620px;"> Right </div>
    </div>



  2. Using CSS display property - which can be used to make divs act like a table:



    <div style="width: 100%; display: table;">
    <div style="display: table-row">
    <div style="width: 600px; display: table-cell;"> Left </div>
    <div style="display: table-cell;"> Right </div>
    </div>
    </div>



There are more methods, but those two are the most popular.






share|improve this answer





















  • 12





    HTML 5 solution from @filoxo, use that instead

    – TheMcMurder
    May 13 '15 at 0:46








  • 1





    What the previous commenter said: consider adding HTML5 solution per filoxo as #3.

    – Ahmed Fasih
    May 26 '15 at 4:54






  • 2





    @TheMcMurder: for us who needs to support old browsers (eg IE < 11), that's not an option.

    – Oyvind
    Jun 24 '16 at 13:52











  • @Oyvind, you're exactly right. It depends on your use case. If you are supporting IE 8, 9, or 10 you would have to polyfill support I'd recommend a service like polyfill.io cdn.polyfill.io/v2/docs or github.com/10up/flexibility but you may have really strict requirements that prevent using polyfills.

    – TheMcMurder
    Jun 27 '16 at 15:38








  • 1





    what does overflow: hidden do? isnt this for elements with a specified height?

    – michael
    Jul 27 '17 at 20:51



















141














CSS3 introduced flexible boxes (aka. flex box) which can also achieve this behavior.



Simply define the width of the first div, and then give the second a flex-grow value of 1 which will allow it to fill the remaining width of the parent.



.container{
display: flex;
}
.fixed{
width: 200px;
}
.flex-item{
flex-grow: 1;
}


<div class="container">
<div class="fixed"></div>
<div class="flex-item"></div>
</div>


jsFiddle demo



Note that flex boxes are not backwards compatible with old browsers, but is a great option for targeting modern browsers (see also Caniuse and MDN). A great comprehensive guide on how to use flex boxes is available on CSS Tricks.






share|improve this answer





















  • 4





    It took all day to find a solution and this answer solved it! I have 4 panels side by side with the 3rd and 4th panels sometimes not having anything in them. They all live in a containing div with a border around them. The whole float:left on the first div situation left me with a div going past the border on the bottom because the labels generated are dynamic. The labels are spans cuz that's how ASP renders them. Not having the float:left made only 3 of the divs on the same row. And a using a table is out of the question. Thank you!

    – Luminous
    Mar 31 '15 at 20:08











  • Is there a backwards compatible method to use something like this, i.e. for us poor saps who still have to support IE 8-10

    – Ben A. Hilleli
    Nov 9 '15 at 21:24











  • @BenA.Hilleli that might depend on your requirements (eg. progressive enhancement or graceful degradation) but a quick search yielded this (a bit out-dated) "How to use flexbox in the real world" guide as well as Flexie.js which supports IE6-9. Alternatively, try out any of the other answers for this question since they achieve the same thing.

    – filoxo
    Nov 22 '15 at 16:50



















10














I don't know much about HTML and CSS design strategies, but if you're looking for something simple and that will fit the screen automatically (as I am) I believe the most straight forward solution is to make the divs behave as words in a paragraph. Try specifying display: inline-block



<div style="display: inline-block">
Content in column A
</div>
<div style="display: inline-block">
Content in column B
</div>


You might or might not need to specify the width of the DIVs






share|improve this answer



















  • 3





    Probably display:flex is the best solution, but I think inline-block is also excellent because it works on more browsers. By the way, you might need to wrap both divs with a <div style="white-space:nowrap"> to prevent break up on resize.

    – John Henckel
    Nov 15 '16 at 14:42











  • This is good solution for templating. The only issue is that it pushes a div with lesser content to the bottom. How to push it to the top?

    – almost a beginner
    Aug 13 '18 at 5:03











  • nvm, just needed to search it, solution is: vertical-align:top;

    – almost a beginner
    Aug 13 '18 at 5:04



















9














You can use CSS grid to achieve this, this is the long-hand version for the purposes of illustration:






div.container {
display: grid;
grid-template-columns: 220px 20px auto;
grid-template-rows: auto;
}

div.left {
grid-column-start: 1;
grid-column-end: 2;
grid-row-start: row1-start
grid-row-end: 3;
background-color: Aqua;
}

div.right {
grid-column-start: 3;
grid-column-end: 4;
grid-row-start: 1;
grid-row-end; 1;
background-color: Silver;
}

div.below {
grid-column-start: 1;
grid-column-end: 4;
grid-row-start: 2;
grid-row-end; 2;
}

<div class="container">
<div class="left">Left</div>
<div class="right">Right</div>
<div class="below">Below</div>
</div>





Or the more traditional method using float and margin.



I have included a background colour in this example to help show where things are - and also what to do with content below the floated-area.



Don't put your styles inline in real life, extract them into a style sheet.






div.left {
width: 200px;
float: left;
background-color: Aqua;
}

div.right {
margin-left: 220px;
background-color: Silver;
}

div.clear {
clear: both;
}

    <div class="left"> Left </div>
<div class="right"> Right </div>
<div class="clear">Below</div>





<div style="width: 200px; float: left; background-color: Aqua;"> Left </div>
<div style="margin-left: 220px; background-color: Silver;"> Right </div>
<div style="clear: both;">Below</div>





share|improve this answer

































    2














    <div class="container" style="width: 100%;">
    <div class="sidebar" style="width: 200px; float: left;">
    Sidebar
    </div>
    <div class="content" style="margin-left: 202px;">
    content
    </div>
    </div>


    This will be cross browser compatible. Without the margin-left you will run into issues with content running all the way to the left if you content is longer than your sidebar.






    share|improve this answer































      1














      Give the first div a float left and fixed with, the second div 100% width an float left. That should do the trick. If you want to place items below it you need a clear:both on the item you want to place below






      share|improve this answer































        1














        If you're not tagetting IE6, then float the second <div> and give it a margin equal to (or maybe a little bigger than) the first <div>'s fixed width.



        HTML:



        <div id="main-wrapper">
        <div id="fixed-width"> lorem ipsum </div>
        <div id="rest-of-space"> dolor sit amet </div>
        </div>


        CSS:



        #main-wrapper {
        100%;
        background:red;
        }
        #fixed-width {
        width:100px;
        float:left
        }
        #rest-of-space {
        margin-left:101px;
        /* May have to increase depending on borders and margin of the fixd width div*/
        background:blue;
        }


        The margin accounts for the possibility that the 'rest-of-space' <div> may contain more content than the 'fixed-width' <div>.



        Don't give the fixed width one a background; if you need to visibly see these as different 'columns' then use the Faux Columns trick.






        share|improve this answer






















          protected by dippas Jan 9 '17 at 2:25



          Thank you for your interest in this question.
          Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



          Would you like to answer one of these unanswered questions instead?














          7 Answers
          7






          active

          oldest

          votes








          7 Answers
          7






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          302














          There are many ways to do what you're asking for:





          1. Using CSS float property:



            <div style="width: 100%; overflow: hidden;">
            <div style="width: 600px; float: left;"> Left </div>
            <div style="margin-left: 620px;"> Right </div>
            </div>



          2. Using CSS display property - which can be used to make divs act like a table:



            <div style="width: 100%; display: table;">
            <div style="display: table-row">
            <div style="width: 600px; display: table-cell;"> Left </div>
            <div style="display: table-cell;"> Right </div>
            </div>
            </div>



          There are more methods, but those two are the most popular.






          share|improve this answer





















          • 12





            HTML 5 solution from @filoxo, use that instead

            – TheMcMurder
            May 13 '15 at 0:46








          • 1





            What the previous commenter said: consider adding HTML5 solution per filoxo as #3.

            – Ahmed Fasih
            May 26 '15 at 4:54






          • 2





            @TheMcMurder: for us who needs to support old browsers (eg IE < 11), that's not an option.

            – Oyvind
            Jun 24 '16 at 13:52











          • @Oyvind, you're exactly right. It depends on your use case. If you are supporting IE 8, 9, or 10 you would have to polyfill support I'd recommend a service like polyfill.io cdn.polyfill.io/v2/docs or github.com/10up/flexibility but you may have really strict requirements that prevent using polyfills.

            – TheMcMurder
            Jun 27 '16 at 15:38








          • 1





            what does overflow: hidden do? isnt this for elements with a specified height?

            – michael
            Jul 27 '17 at 20:51
















          302














          There are many ways to do what you're asking for:





          1. Using CSS float property:



            <div style="width: 100%; overflow: hidden;">
            <div style="width: 600px; float: left;"> Left </div>
            <div style="margin-left: 620px;"> Right </div>
            </div>



          2. Using CSS display property - which can be used to make divs act like a table:



            <div style="width: 100%; display: table;">
            <div style="display: table-row">
            <div style="width: 600px; display: table-cell;"> Left </div>
            <div style="display: table-cell;"> Right </div>
            </div>
            </div>



          There are more methods, but those two are the most popular.






          share|improve this answer





















          • 12





            HTML 5 solution from @filoxo, use that instead

            – TheMcMurder
            May 13 '15 at 0:46








          • 1





            What the previous commenter said: consider adding HTML5 solution per filoxo as #3.

            – Ahmed Fasih
            May 26 '15 at 4:54






          • 2





            @TheMcMurder: for us who needs to support old browsers (eg IE < 11), that's not an option.

            – Oyvind
            Jun 24 '16 at 13:52











          • @Oyvind, you're exactly right. It depends on your use case. If you are supporting IE 8, 9, or 10 you would have to polyfill support I'd recommend a service like polyfill.io cdn.polyfill.io/v2/docs or github.com/10up/flexibility but you may have really strict requirements that prevent using polyfills.

            – TheMcMurder
            Jun 27 '16 at 15:38








          • 1





            what does overflow: hidden do? isnt this for elements with a specified height?

            – michael
            Jul 27 '17 at 20:51














          302












          302








          302







          There are many ways to do what you're asking for:





          1. Using CSS float property:



            <div style="width: 100%; overflow: hidden;">
            <div style="width: 600px; float: left;"> Left </div>
            <div style="margin-left: 620px;"> Right </div>
            </div>



          2. Using CSS display property - which can be used to make divs act like a table:



            <div style="width: 100%; display: table;">
            <div style="display: table-row">
            <div style="width: 600px; display: table-cell;"> Left </div>
            <div style="display: table-cell;"> Right </div>
            </div>
            </div>



          There are more methods, but those two are the most popular.






          share|improve this answer















          There are many ways to do what you're asking for:





          1. Using CSS float property:



            <div style="width: 100%; overflow: hidden;">
            <div style="width: 600px; float: left;"> Left </div>
            <div style="margin-left: 620px;"> Right </div>
            </div>



          2. Using CSS display property - which can be used to make divs act like a table:



            <div style="width: 100%; display: table;">
            <div style="display: table-row">
            <div style="width: 600px; display: table-cell;"> Left </div>
            <div style="display: table-cell;"> Right </div>
            </div>
            </div>



          There are more methods, but those two are the most popular.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 12 '14 at 20:47

























          answered Apr 14 '10 at 13:37









          CrozinCrozin

          35.5k1076122




          35.5k1076122








          • 12





            HTML 5 solution from @filoxo, use that instead

            – TheMcMurder
            May 13 '15 at 0:46








          • 1





            What the previous commenter said: consider adding HTML5 solution per filoxo as #3.

            – Ahmed Fasih
            May 26 '15 at 4:54






          • 2





            @TheMcMurder: for us who needs to support old browsers (eg IE < 11), that's not an option.

            – Oyvind
            Jun 24 '16 at 13:52











          • @Oyvind, you're exactly right. It depends on your use case. If you are supporting IE 8, 9, or 10 you would have to polyfill support I'd recommend a service like polyfill.io cdn.polyfill.io/v2/docs or github.com/10up/flexibility but you may have really strict requirements that prevent using polyfills.

            – TheMcMurder
            Jun 27 '16 at 15:38








          • 1





            what does overflow: hidden do? isnt this for elements with a specified height?

            – michael
            Jul 27 '17 at 20:51














          • 12





            HTML 5 solution from @filoxo, use that instead

            – TheMcMurder
            May 13 '15 at 0:46








          • 1





            What the previous commenter said: consider adding HTML5 solution per filoxo as #3.

            – Ahmed Fasih
            May 26 '15 at 4:54






          • 2





            @TheMcMurder: for us who needs to support old browsers (eg IE < 11), that's not an option.

            – Oyvind
            Jun 24 '16 at 13:52











          • @Oyvind, you're exactly right. It depends on your use case. If you are supporting IE 8, 9, or 10 you would have to polyfill support I'd recommend a service like polyfill.io cdn.polyfill.io/v2/docs or github.com/10up/flexibility but you may have really strict requirements that prevent using polyfills.

            – TheMcMurder
            Jun 27 '16 at 15:38








          • 1





            what does overflow: hidden do? isnt this for elements with a specified height?

            – michael
            Jul 27 '17 at 20:51








          12




          12





          HTML 5 solution from @filoxo, use that instead

          – TheMcMurder
          May 13 '15 at 0:46







          HTML 5 solution from @filoxo, use that instead

          – TheMcMurder
          May 13 '15 at 0:46






          1




          1





          What the previous commenter said: consider adding HTML5 solution per filoxo as #3.

          – Ahmed Fasih
          May 26 '15 at 4:54





          What the previous commenter said: consider adding HTML5 solution per filoxo as #3.

          – Ahmed Fasih
          May 26 '15 at 4:54




          2




          2





          @TheMcMurder: for us who needs to support old browsers (eg IE < 11), that's not an option.

          – Oyvind
          Jun 24 '16 at 13:52





          @TheMcMurder: for us who needs to support old browsers (eg IE < 11), that's not an option.

          – Oyvind
          Jun 24 '16 at 13:52













          @Oyvind, you're exactly right. It depends on your use case. If you are supporting IE 8, 9, or 10 you would have to polyfill support I'd recommend a service like polyfill.io cdn.polyfill.io/v2/docs or github.com/10up/flexibility but you may have really strict requirements that prevent using polyfills.

          – TheMcMurder
          Jun 27 '16 at 15:38







          @Oyvind, you're exactly right. It depends on your use case. If you are supporting IE 8, 9, or 10 you would have to polyfill support I'd recommend a service like polyfill.io cdn.polyfill.io/v2/docs or github.com/10up/flexibility but you may have really strict requirements that prevent using polyfills.

          – TheMcMurder
          Jun 27 '16 at 15:38






          1




          1





          what does overflow: hidden do? isnt this for elements with a specified height?

          – michael
          Jul 27 '17 at 20:51





          what does overflow: hidden do? isnt this for elements with a specified height?

          – michael
          Jul 27 '17 at 20:51













          141














          CSS3 introduced flexible boxes (aka. flex box) which can also achieve this behavior.



          Simply define the width of the first div, and then give the second a flex-grow value of 1 which will allow it to fill the remaining width of the parent.



          .container{
          display: flex;
          }
          .fixed{
          width: 200px;
          }
          .flex-item{
          flex-grow: 1;
          }


          <div class="container">
          <div class="fixed"></div>
          <div class="flex-item"></div>
          </div>


          jsFiddle demo



          Note that flex boxes are not backwards compatible with old browsers, but is a great option for targeting modern browsers (see also Caniuse and MDN). A great comprehensive guide on how to use flex boxes is available on CSS Tricks.






          share|improve this answer





















          • 4





            It took all day to find a solution and this answer solved it! I have 4 panels side by side with the 3rd and 4th panels sometimes not having anything in them. They all live in a containing div with a border around them. The whole float:left on the first div situation left me with a div going past the border on the bottom because the labels generated are dynamic. The labels are spans cuz that's how ASP renders them. Not having the float:left made only 3 of the divs on the same row. And a using a table is out of the question. Thank you!

            – Luminous
            Mar 31 '15 at 20:08











          • Is there a backwards compatible method to use something like this, i.e. for us poor saps who still have to support IE 8-10

            – Ben A. Hilleli
            Nov 9 '15 at 21:24











          • @BenA.Hilleli that might depend on your requirements (eg. progressive enhancement or graceful degradation) but a quick search yielded this (a bit out-dated) "How to use flexbox in the real world" guide as well as Flexie.js which supports IE6-9. Alternatively, try out any of the other answers for this question since they achieve the same thing.

            – filoxo
            Nov 22 '15 at 16:50
















          141














          CSS3 introduced flexible boxes (aka. flex box) which can also achieve this behavior.



          Simply define the width of the first div, and then give the second a flex-grow value of 1 which will allow it to fill the remaining width of the parent.



          .container{
          display: flex;
          }
          .fixed{
          width: 200px;
          }
          .flex-item{
          flex-grow: 1;
          }


          <div class="container">
          <div class="fixed"></div>
          <div class="flex-item"></div>
          </div>


          jsFiddle demo



          Note that flex boxes are not backwards compatible with old browsers, but is a great option for targeting modern browsers (see also Caniuse and MDN). A great comprehensive guide on how to use flex boxes is available on CSS Tricks.






          share|improve this answer





















          • 4





            It took all day to find a solution and this answer solved it! I have 4 panels side by side with the 3rd and 4th panels sometimes not having anything in them. They all live in a containing div with a border around them. The whole float:left on the first div situation left me with a div going past the border on the bottom because the labels generated are dynamic. The labels are spans cuz that's how ASP renders them. Not having the float:left made only 3 of the divs on the same row. And a using a table is out of the question. Thank you!

            – Luminous
            Mar 31 '15 at 20:08











          • Is there a backwards compatible method to use something like this, i.e. for us poor saps who still have to support IE 8-10

            – Ben A. Hilleli
            Nov 9 '15 at 21:24











          • @BenA.Hilleli that might depend on your requirements (eg. progressive enhancement or graceful degradation) but a quick search yielded this (a bit out-dated) "How to use flexbox in the real world" guide as well as Flexie.js which supports IE6-9. Alternatively, try out any of the other answers for this question since they achieve the same thing.

            – filoxo
            Nov 22 '15 at 16:50














          141












          141








          141







          CSS3 introduced flexible boxes (aka. flex box) which can also achieve this behavior.



          Simply define the width of the first div, and then give the second a flex-grow value of 1 which will allow it to fill the remaining width of the parent.



          .container{
          display: flex;
          }
          .fixed{
          width: 200px;
          }
          .flex-item{
          flex-grow: 1;
          }


          <div class="container">
          <div class="fixed"></div>
          <div class="flex-item"></div>
          </div>


          jsFiddle demo



          Note that flex boxes are not backwards compatible with old browsers, but is a great option for targeting modern browsers (see also Caniuse and MDN). A great comprehensive guide on how to use flex boxes is available on CSS Tricks.






          share|improve this answer















          CSS3 introduced flexible boxes (aka. flex box) which can also achieve this behavior.



          Simply define the width of the first div, and then give the second a flex-grow value of 1 which will allow it to fill the remaining width of the parent.



          .container{
          display: flex;
          }
          .fixed{
          width: 200px;
          }
          .flex-item{
          flex-grow: 1;
          }


          <div class="container">
          <div class="fixed"></div>
          <div class="flex-item"></div>
          </div>


          jsFiddle demo



          Note that flex boxes are not backwards compatible with old browsers, but is a great option for targeting modern browsers (see also Caniuse and MDN). A great comprehensive guide on how to use flex boxes is available on CSS Tricks.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jul 3 '16 at 0:59

























          answered Jun 18 '14 at 18:25









          filoxofiloxo

          4,66522331




          4,66522331








          • 4





            It took all day to find a solution and this answer solved it! I have 4 panels side by side with the 3rd and 4th panels sometimes not having anything in them. They all live in a containing div with a border around them. The whole float:left on the first div situation left me with a div going past the border on the bottom because the labels generated are dynamic. The labels are spans cuz that's how ASP renders them. Not having the float:left made only 3 of the divs on the same row. And a using a table is out of the question. Thank you!

            – Luminous
            Mar 31 '15 at 20:08











          • Is there a backwards compatible method to use something like this, i.e. for us poor saps who still have to support IE 8-10

            – Ben A. Hilleli
            Nov 9 '15 at 21:24











          • @BenA.Hilleli that might depend on your requirements (eg. progressive enhancement or graceful degradation) but a quick search yielded this (a bit out-dated) "How to use flexbox in the real world" guide as well as Flexie.js which supports IE6-9. Alternatively, try out any of the other answers for this question since they achieve the same thing.

            – filoxo
            Nov 22 '15 at 16:50














          • 4





            It took all day to find a solution and this answer solved it! I have 4 panels side by side with the 3rd and 4th panels sometimes not having anything in them. They all live in a containing div with a border around them. The whole float:left on the first div situation left me with a div going past the border on the bottom because the labels generated are dynamic. The labels are spans cuz that's how ASP renders them. Not having the float:left made only 3 of the divs on the same row. And a using a table is out of the question. Thank you!

            – Luminous
            Mar 31 '15 at 20:08











          • Is there a backwards compatible method to use something like this, i.e. for us poor saps who still have to support IE 8-10

            – Ben A. Hilleli
            Nov 9 '15 at 21:24











          • @BenA.Hilleli that might depend on your requirements (eg. progressive enhancement or graceful degradation) but a quick search yielded this (a bit out-dated) "How to use flexbox in the real world" guide as well as Flexie.js which supports IE6-9. Alternatively, try out any of the other answers for this question since they achieve the same thing.

            – filoxo
            Nov 22 '15 at 16:50








          4




          4





          It took all day to find a solution and this answer solved it! I have 4 panels side by side with the 3rd and 4th panels sometimes not having anything in them. They all live in a containing div with a border around them. The whole float:left on the first div situation left me with a div going past the border on the bottom because the labels generated are dynamic. The labels are spans cuz that's how ASP renders them. Not having the float:left made only 3 of the divs on the same row. And a using a table is out of the question. Thank you!

          – Luminous
          Mar 31 '15 at 20:08





          It took all day to find a solution and this answer solved it! I have 4 panels side by side with the 3rd and 4th panels sometimes not having anything in them. They all live in a containing div with a border around them. The whole float:left on the first div situation left me with a div going past the border on the bottom because the labels generated are dynamic. The labels are spans cuz that's how ASP renders them. Not having the float:left made only 3 of the divs on the same row. And a using a table is out of the question. Thank you!

          – Luminous
          Mar 31 '15 at 20:08













          Is there a backwards compatible method to use something like this, i.e. for us poor saps who still have to support IE 8-10

          – Ben A. Hilleli
          Nov 9 '15 at 21:24





          Is there a backwards compatible method to use something like this, i.e. for us poor saps who still have to support IE 8-10

          – Ben A. Hilleli
          Nov 9 '15 at 21:24













          @BenA.Hilleli that might depend on your requirements (eg. progressive enhancement or graceful degradation) but a quick search yielded this (a bit out-dated) "How to use flexbox in the real world" guide as well as Flexie.js which supports IE6-9. Alternatively, try out any of the other answers for this question since they achieve the same thing.

          – filoxo
          Nov 22 '15 at 16:50





          @BenA.Hilleli that might depend on your requirements (eg. progressive enhancement or graceful degradation) but a quick search yielded this (a bit out-dated) "How to use flexbox in the real world" guide as well as Flexie.js which supports IE6-9. Alternatively, try out any of the other answers for this question since they achieve the same thing.

          – filoxo
          Nov 22 '15 at 16:50











          10














          I don't know much about HTML and CSS design strategies, but if you're looking for something simple and that will fit the screen automatically (as I am) I believe the most straight forward solution is to make the divs behave as words in a paragraph. Try specifying display: inline-block



          <div style="display: inline-block">
          Content in column A
          </div>
          <div style="display: inline-block">
          Content in column B
          </div>


          You might or might not need to specify the width of the DIVs






          share|improve this answer



















          • 3





            Probably display:flex is the best solution, but I think inline-block is also excellent because it works on more browsers. By the way, you might need to wrap both divs with a <div style="white-space:nowrap"> to prevent break up on resize.

            – John Henckel
            Nov 15 '16 at 14:42











          • This is good solution for templating. The only issue is that it pushes a div with lesser content to the bottom. How to push it to the top?

            – almost a beginner
            Aug 13 '18 at 5:03











          • nvm, just needed to search it, solution is: vertical-align:top;

            – almost a beginner
            Aug 13 '18 at 5:04
















          10














          I don't know much about HTML and CSS design strategies, but if you're looking for something simple and that will fit the screen automatically (as I am) I believe the most straight forward solution is to make the divs behave as words in a paragraph. Try specifying display: inline-block



          <div style="display: inline-block">
          Content in column A
          </div>
          <div style="display: inline-block">
          Content in column B
          </div>


          You might or might not need to specify the width of the DIVs






          share|improve this answer



















          • 3





            Probably display:flex is the best solution, but I think inline-block is also excellent because it works on more browsers. By the way, you might need to wrap both divs with a <div style="white-space:nowrap"> to prevent break up on resize.

            – John Henckel
            Nov 15 '16 at 14:42











          • This is good solution for templating. The only issue is that it pushes a div with lesser content to the bottom. How to push it to the top?

            – almost a beginner
            Aug 13 '18 at 5:03











          • nvm, just needed to search it, solution is: vertical-align:top;

            – almost a beginner
            Aug 13 '18 at 5:04














          10












          10








          10







          I don't know much about HTML and CSS design strategies, but if you're looking for something simple and that will fit the screen automatically (as I am) I believe the most straight forward solution is to make the divs behave as words in a paragraph. Try specifying display: inline-block



          <div style="display: inline-block">
          Content in column A
          </div>
          <div style="display: inline-block">
          Content in column B
          </div>


          You might or might not need to specify the width of the DIVs






          share|improve this answer













          I don't know much about HTML and CSS design strategies, but if you're looking for something simple and that will fit the screen automatically (as I am) I believe the most straight forward solution is to make the divs behave as words in a paragraph. Try specifying display: inline-block



          <div style="display: inline-block">
          Content in column A
          </div>
          <div style="display: inline-block">
          Content in column B
          </div>


          You might or might not need to specify the width of the DIVs







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 27 '15 at 20:22









          Guillermo RuffinoGuillermo Ruffino

          2,19111816




          2,19111816








          • 3





            Probably display:flex is the best solution, but I think inline-block is also excellent because it works on more browsers. By the way, you might need to wrap both divs with a <div style="white-space:nowrap"> to prevent break up on resize.

            – John Henckel
            Nov 15 '16 at 14:42











          • This is good solution for templating. The only issue is that it pushes a div with lesser content to the bottom. How to push it to the top?

            – almost a beginner
            Aug 13 '18 at 5:03











          • nvm, just needed to search it, solution is: vertical-align:top;

            – almost a beginner
            Aug 13 '18 at 5:04














          • 3





            Probably display:flex is the best solution, but I think inline-block is also excellent because it works on more browsers. By the way, you might need to wrap both divs with a <div style="white-space:nowrap"> to prevent break up on resize.

            – John Henckel
            Nov 15 '16 at 14:42











          • This is good solution for templating. The only issue is that it pushes a div with lesser content to the bottom. How to push it to the top?

            – almost a beginner
            Aug 13 '18 at 5:03











          • nvm, just needed to search it, solution is: vertical-align:top;

            – almost a beginner
            Aug 13 '18 at 5:04








          3




          3





          Probably display:flex is the best solution, but I think inline-block is also excellent because it works on more browsers. By the way, you might need to wrap both divs with a <div style="white-space:nowrap"> to prevent break up on resize.

          – John Henckel
          Nov 15 '16 at 14:42





          Probably display:flex is the best solution, but I think inline-block is also excellent because it works on more browsers. By the way, you might need to wrap both divs with a <div style="white-space:nowrap"> to prevent break up on resize.

          – John Henckel
          Nov 15 '16 at 14:42













          This is good solution for templating. The only issue is that it pushes a div with lesser content to the bottom. How to push it to the top?

          – almost a beginner
          Aug 13 '18 at 5:03





          This is good solution for templating. The only issue is that it pushes a div with lesser content to the bottom. How to push it to the top?

          – almost a beginner
          Aug 13 '18 at 5:03













          nvm, just needed to search it, solution is: vertical-align:top;

          – almost a beginner
          Aug 13 '18 at 5:04





          nvm, just needed to search it, solution is: vertical-align:top;

          – almost a beginner
          Aug 13 '18 at 5:04











          9














          You can use CSS grid to achieve this, this is the long-hand version for the purposes of illustration:






          div.container {
          display: grid;
          grid-template-columns: 220px 20px auto;
          grid-template-rows: auto;
          }

          div.left {
          grid-column-start: 1;
          grid-column-end: 2;
          grid-row-start: row1-start
          grid-row-end: 3;
          background-color: Aqua;
          }

          div.right {
          grid-column-start: 3;
          grid-column-end: 4;
          grid-row-start: 1;
          grid-row-end; 1;
          background-color: Silver;
          }

          div.below {
          grid-column-start: 1;
          grid-column-end: 4;
          grid-row-start: 2;
          grid-row-end; 2;
          }

          <div class="container">
          <div class="left">Left</div>
          <div class="right">Right</div>
          <div class="below">Below</div>
          </div>





          Or the more traditional method using float and margin.



          I have included a background colour in this example to help show where things are - and also what to do with content below the floated-area.



          Don't put your styles inline in real life, extract them into a style sheet.






          div.left {
          width: 200px;
          float: left;
          background-color: Aqua;
          }

          div.right {
          margin-left: 220px;
          background-color: Silver;
          }

          div.clear {
          clear: both;
          }

              <div class="left"> Left </div>
          <div class="right"> Right </div>
          <div class="clear">Below</div>





          <div style="width: 200px; float: left; background-color: Aqua;"> Left </div>
          <div style="margin-left: 220px; background-color: Silver;"> Right </div>
          <div style="clear: both;">Below</div>





          share|improve this answer






























            9














            You can use CSS grid to achieve this, this is the long-hand version for the purposes of illustration:






            div.container {
            display: grid;
            grid-template-columns: 220px 20px auto;
            grid-template-rows: auto;
            }

            div.left {
            grid-column-start: 1;
            grid-column-end: 2;
            grid-row-start: row1-start
            grid-row-end: 3;
            background-color: Aqua;
            }

            div.right {
            grid-column-start: 3;
            grid-column-end: 4;
            grid-row-start: 1;
            grid-row-end; 1;
            background-color: Silver;
            }

            div.below {
            grid-column-start: 1;
            grid-column-end: 4;
            grid-row-start: 2;
            grid-row-end; 2;
            }

            <div class="container">
            <div class="left">Left</div>
            <div class="right">Right</div>
            <div class="below">Below</div>
            </div>





            Or the more traditional method using float and margin.



            I have included a background colour in this example to help show where things are - and also what to do with content below the floated-area.



            Don't put your styles inline in real life, extract them into a style sheet.






            div.left {
            width: 200px;
            float: left;
            background-color: Aqua;
            }

            div.right {
            margin-left: 220px;
            background-color: Silver;
            }

            div.clear {
            clear: both;
            }

                <div class="left"> Left </div>
            <div class="right"> Right </div>
            <div class="clear">Below</div>





            <div style="width: 200px; float: left; background-color: Aqua;"> Left </div>
            <div style="margin-left: 220px; background-color: Silver;"> Right </div>
            <div style="clear: both;">Below</div>





            share|improve this answer




























              9












              9








              9







              You can use CSS grid to achieve this, this is the long-hand version for the purposes of illustration:






              div.container {
              display: grid;
              grid-template-columns: 220px 20px auto;
              grid-template-rows: auto;
              }

              div.left {
              grid-column-start: 1;
              grid-column-end: 2;
              grid-row-start: row1-start
              grid-row-end: 3;
              background-color: Aqua;
              }

              div.right {
              grid-column-start: 3;
              grid-column-end: 4;
              grid-row-start: 1;
              grid-row-end; 1;
              background-color: Silver;
              }

              div.below {
              grid-column-start: 1;
              grid-column-end: 4;
              grid-row-start: 2;
              grid-row-end; 2;
              }

              <div class="container">
              <div class="left">Left</div>
              <div class="right">Right</div>
              <div class="below">Below</div>
              </div>





              Or the more traditional method using float and margin.



              I have included a background colour in this example to help show where things are - and also what to do with content below the floated-area.



              Don't put your styles inline in real life, extract them into a style sheet.






              div.left {
              width: 200px;
              float: left;
              background-color: Aqua;
              }

              div.right {
              margin-left: 220px;
              background-color: Silver;
              }

              div.clear {
              clear: both;
              }

                  <div class="left"> Left </div>
              <div class="right"> Right </div>
              <div class="clear">Below</div>





              <div style="width: 200px; float: left; background-color: Aqua;"> Left </div>
              <div style="margin-left: 220px; background-color: Silver;"> Right </div>
              <div style="clear: both;">Below</div>





              share|improve this answer















              You can use CSS grid to achieve this, this is the long-hand version for the purposes of illustration:






              div.container {
              display: grid;
              grid-template-columns: 220px 20px auto;
              grid-template-rows: auto;
              }

              div.left {
              grid-column-start: 1;
              grid-column-end: 2;
              grid-row-start: row1-start
              grid-row-end: 3;
              background-color: Aqua;
              }

              div.right {
              grid-column-start: 3;
              grid-column-end: 4;
              grid-row-start: 1;
              grid-row-end; 1;
              background-color: Silver;
              }

              div.below {
              grid-column-start: 1;
              grid-column-end: 4;
              grid-row-start: 2;
              grid-row-end; 2;
              }

              <div class="container">
              <div class="left">Left</div>
              <div class="right">Right</div>
              <div class="below">Below</div>
              </div>





              Or the more traditional method using float and margin.



              I have included a background colour in this example to help show where things are - and also what to do with content below the floated-area.



              Don't put your styles inline in real life, extract them into a style sheet.






              div.left {
              width: 200px;
              float: left;
              background-color: Aqua;
              }

              div.right {
              margin-left: 220px;
              background-color: Silver;
              }

              div.clear {
              clear: both;
              }

                  <div class="left"> Left </div>
              <div class="right"> Right </div>
              <div class="clear">Below</div>





              <div style="width: 200px; float: left; background-color: Aqua;"> Left </div>
              <div style="margin-left: 220px; background-color: Silver;"> Right </div>
              <div style="clear: both;">Below</div>





              div.container {
              display: grid;
              grid-template-columns: 220px 20px auto;
              grid-template-rows: auto;
              }

              div.left {
              grid-column-start: 1;
              grid-column-end: 2;
              grid-row-start: row1-start
              grid-row-end: 3;
              background-color: Aqua;
              }

              div.right {
              grid-column-start: 3;
              grid-column-end: 4;
              grid-row-start: 1;
              grid-row-end; 1;
              background-color: Silver;
              }

              div.below {
              grid-column-start: 1;
              grid-column-end: 4;
              grid-row-start: 2;
              grid-row-end; 2;
              }

              <div class="container">
              <div class="left">Left</div>
              <div class="right">Right</div>
              <div class="below">Below</div>
              </div>





              div.container {
              display: grid;
              grid-template-columns: 220px 20px auto;
              grid-template-rows: auto;
              }

              div.left {
              grid-column-start: 1;
              grid-column-end: 2;
              grid-row-start: row1-start
              grid-row-end: 3;
              background-color: Aqua;
              }

              div.right {
              grid-column-start: 3;
              grid-column-end: 4;
              grid-row-start: 1;
              grid-row-end; 1;
              background-color: Silver;
              }

              div.below {
              grid-column-start: 1;
              grid-column-end: 4;
              grid-row-start: 2;
              grid-row-end; 2;
              }

              <div class="container">
              <div class="left">Left</div>
              <div class="right">Right</div>
              <div class="below">Below</div>
              </div>





              div.left {
              width: 200px;
              float: left;
              background-color: Aqua;
              }

              div.right {
              margin-left: 220px;
              background-color: Silver;
              }

              div.clear {
              clear: both;
              }

                  <div class="left"> Left </div>
              <div class="right"> Right </div>
              <div class="clear">Below</div>





              div.left {
              width: 200px;
              float: left;
              background-color: Aqua;
              }

              div.right {
              margin-left: 220px;
              background-color: Silver;
              }

              div.clear {
              clear: both;
              }

                  <div class="left"> Left </div>
              <div class="right"> Right </div>
              <div class="clear">Below</div>






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 27 '18 at 11:59

























              answered Apr 14 '10 at 13:43









              FentonFenton

              155k44291315




              155k44291315























                  2














                  <div class="container" style="width: 100%;">
                  <div class="sidebar" style="width: 200px; float: left;">
                  Sidebar
                  </div>
                  <div class="content" style="margin-left: 202px;">
                  content
                  </div>
                  </div>


                  This will be cross browser compatible. Without the margin-left you will run into issues with content running all the way to the left if you content is longer than your sidebar.






                  share|improve this answer




























                    2














                    <div class="container" style="width: 100%;">
                    <div class="sidebar" style="width: 200px; float: left;">
                    Sidebar
                    </div>
                    <div class="content" style="margin-left: 202px;">
                    content
                    </div>
                    </div>


                    This will be cross browser compatible. Without the margin-left you will run into issues with content running all the way to the left if you content is longer than your sidebar.






                    share|improve this answer


























                      2












                      2








                      2







                      <div class="container" style="width: 100%;">
                      <div class="sidebar" style="width: 200px; float: left;">
                      Sidebar
                      </div>
                      <div class="content" style="margin-left: 202px;">
                      content
                      </div>
                      </div>


                      This will be cross browser compatible. Without the margin-left you will run into issues with content running all the way to the left if you content is longer than your sidebar.






                      share|improve this answer













                      <div class="container" style="width: 100%;">
                      <div class="sidebar" style="width: 200px; float: left;">
                      Sidebar
                      </div>
                      <div class="content" style="margin-left: 202px;">
                      content
                      </div>
                      </div>


                      This will be cross browser compatible. Without the margin-left you will run into issues with content running all the way to the left if you content is longer than your sidebar.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Apr 14 '10 at 13:48









                      RDLRDL

                      6,68622330




                      6,68622330























                          1














                          Give the first div a float left and fixed with, the second div 100% width an float left. That should do the trick. If you want to place items below it you need a clear:both on the item you want to place below






                          share|improve this answer




























                            1














                            Give the first div a float left and fixed with, the second div 100% width an float left. That should do the trick. If you want to place items below it you need a clear:both on the item you want to place below






                            share|improve this answer


























                              1












                              1








                              1







                              Give the first div a float left and fixed with, the second div 100% width an float left. That should do the trick. If you want to place items below it you need a clear:both on the item you want to place below






                              share|improve this answer













                              Give the first div a float left and fixed with, the second div 100% width an float left. That should do the trick. If you want to place items below it you need a clear:both on the item you want to place below







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Apr 14 '10 at 13:34









                              RobRob

                              3,63094077




                              3,63094077























                                  1














                                  If you're not tagetting IE6, then float the second <div> and give it a margin equal to (or maybe a little bigger than) the first <div>'s fixed width.



                                  HTML:



                                  <div id="main-wrapper">
                                  <div id="fixed-width"> lorem ipsum </div>
                                  <div id="rest-of-space"> dolor sit amet </div>
                                  </div>


                                  CSS:



                                  #main-wrapper {
                                  100%;
                                  background:red;
                                  }
                                  #fixed-width {
                                  width:100px;
                                  float:left
                                  }
                                  #rest-of-space {
                                  margin-left:101px;
                                  /* May have to increase depending on borders and margin of the fixd width div*/
                                  background:blue;
                                  }


                                  The margin accounts for the possibility that the 'rest-of-space' <div> may contain more content than the 'fixed-width' <div>.



                                  Don't give the fixed width one a background; if you need to visibly see these as different 'columns' then use the Faux Columns trick.






                                  share|improve this answer




























                                    1














                                    If you're not tagetting IE6, then float the second <div> and give it a margin equal to (or maybe a little bigger than) the first <div>'s fixed width.



                                    HTML:



                                    <div id="main-wrapper">
                                    <div id="fixed-width"> lorem ipsum </div>
                                    <div id="rest-of-space"> dolor sit amet </div>
                                    </div>


                                    CSS:



                                    #main-wrapper {
                                    100%;
                                    background:red;
                                    }
                                    #fixed-width {
                                    width:100px;
                                    float:left
                                    }
                                    #rest-of-space {
                                    margin-left:101px;
                                    /* May have to increase depending on borders and margin of the fixd width div*/
                                    background:blue;
                                    }


                                    The margin accounts for the possibility that the 'rest-of-space' <div> may contain more content than the 'fixed-width' <div>.



                                    Don't give the fixed width one a background; if you need to visibly see these as different 'columns' then use the Faux Columns trick.






                                    share|improve this answer


























                                      1












                                      1








                                      1







                                      If you're not tagetting IE6, then float the second <div> and give it a margin equal to (or maybe a little bigger than) the first <div>'s fixed width.



                                      HTML:



                                      <div id="main-wrapper">
                                      <div id="fixed-width"> lorem ipsum </div>
                                      <div id="rest-of-space"> dolor sit amet </div>
                                      </div>


                                      CSS:



                                      #main-wrapper {
                                      100%;
                                      background:red;
                                      }
                                      #fixed-width {
                                      width:100px;
                                      float:left
                                      }
                                      #rest-of-space {
                                      margin-left:101px;
                                      /* May have to increase depending on borders and margin of the fixd width div*/
                                      background:blue;
                                      }


                                      The margin accounts for the possibility that the 'rest-of-space' <div> may contain more content than the 'fixed-width' <div>.



                                      Don't give the fixed width one a background; if you need to visibly see these as different 'columns' then use the Faux Columns trick.






                                      share|improve this answer













                                      If you're not tagetting IE6, then float the second <div> and give it a margin equal to (or maybe a little bigger than) the first <div>'s fixed width.



                                      HTML:



                                      <div id="main-wrapper">
                                      <div id="fixed-width"> lorem ipsum </div>
                                      <div id="rest-of-space"> dolor sit amet </div>
                                      </div>


                                      CSS:



                                      #main-wrapper {
                                      100%;
                                      background:red;
                                      }
                                      #fixed-width {
                                      width:100px;
                                      float:left
                                      }
                                      #rest-of-space {
                                      margin-left:101px;
                                      /* May have to increase depending on borders and margin of the fixd width div*/
                                      background:blue;
                                      }


                                      The margin accounts for the possibility that the 'rest-of-space' <div> may contain more content than the 'fixed-width' <div>.



                                      Don't give the fixed width one a background; if you need to visibly see these as different 'columns' then use the Faux Columns trick.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Apr 14 '10 at 13:41









                                      Richard JP Le GuenRichard JP Le Guen

                                      22.8k674111




                                      22.8k674111

















                                          protected by dippas Jan 9 '17 at 2:25



                                          Thank you for your interest in this question.
                                          Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                          Would you like to answer one of these unanswered questions instead?



                                          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)