Dividing div to 2 columns










1















I have seen some solutions to this problem but when I add inside the divs an angular2 component, it doesn't work.



Here is what I got so far:
enter image description here



Code:



<div id="container">
<div id="categoriesContainer">
<categories (onCategoryChanged)="categoryChanged($event)"></categories>
</div>
<div id="products-container">
<product-details *ngFor="let product of products$ | async" id="prodcut"
[product]="product"
[canAddProductToCart]="canAddToCart(product.$key) | async"
(onAddToCart)="addToCart($event)"></product-details>
<button md-button
*ngIf="!showCreateProductComponent"
id="create-product-button"
[disabled]="disableCreateProductButton$ |async"
(click)="showCreateProductComponent=true">
<i class="material-icons">add</i>
</button>
<create-product id="create-product"
(onCencel)="showCreateProductComponent=false"
(onCreateProduct)="onCreateProduct($event)"
*ngIf="showCreateProductComponent"></create-product>
</div>
<div style="clear: both"></div>
</div>


css:



//spliting the div to 2 columns
#container

border-style:solid;
border-width: 1px;
border-color: green;
padding: 10px;
margin: 10px

#categoriesContainer

width: 15%;
border-style: solid;
border-width: 1px;
border-color: blue;
float: left;

#products-container

border-style: solid;
border-width: 1px;
width: 85%;
border-color: red;


//for the angular2 compoennts
#prodcut

float: left;
margin-right: 10px;
margin-bottom: 10px;

#create-product

float: left;
margin-right: 10px;
margin-bottom: 10px;

#create-product-button

float: left;
margin-right: 10px;
margin-bottom: 10px;



Here is what I want: (the cards will be only in the red squer.)



enter image description here



Questions:



  1. How to fix this and why its working great when I remove the angular2 components and replace them with some simple html text?


  2. Can I summerise this code without effecting anything:



    <div id="categoriesContainer"
    style="width: 15%;border-style: solid;border-width: 1px;border-color: blue;float: left">
    <categories (onCategoryChanged)="categoryChanged($event)"></categories>




to:



<categories id="categoriesContainer"
style="width: 15%;border-style: solid;border-width: 1px;border-color: blue;float: left"
(onCategoryChanged)="categoryChanged($event)"></categories>


Thanks alot!










share|improve this question




























    1















    I have seen some solutions to this problem but when I add inside the divs an angular2 component, it doesn't work.



    Here is what I got so far:
    enter image description here



    Code:



    <div id="container">
    <div id="categoriesContainer">
    <categories (onCategoryChanged)="categoryChanged($event)"></categories>
    </div>
    <div id="products-container">
    <product-details *ngFor="let product of products$ | async" id="prodcut"
    [product]="product"
    [canAddProductToCart]="canAddToCart(product.$key) | async"
    (onAddToCart)="addToCart($event)"></product-details>
    <button md-button
    *ngIf="!showCreateProductComponent"
    id="create-product-button"
    [disabled]="disableCreateProductButton$ |async"
    (click)="showCreateProductComponent=true">
    <i class="material-icons">add</i>
    </button>
    <create-product id="create-product"
    (onCencel)="showCreateProductComponent=false"
    (onCreateProduct)="onCreateProduct($event)"
    *ngIf="showCreateProductComponent"></create-product>
    </div>
    <div style="clear: both"></div>
    </div>


    css:



    //spliting the div to 2 columns
    #container

    border-style:solid;
    border-width: 1px;
    border-color: green;
    padding: 10px;
    margin: 10px

    #categoriesContainer

    width: 15%;
    border-style: solid;
    border-width: 1px;
    border-color: blue;
    float: left;

    #products-container

    border-style: solid;
    border-width: 1px;
    width: 85%;
    border-color: red;


    //for the angular2 compoennts
    #prodcut

    float: left;
    margin-right: 10px;
    margin-bottom: 10px;

    #create-product

    float: left;
    margin-right: 10px;
    margin-bottom: 10px;

    #create-product-button

    float: left;
    margin-right: 10px;
    margin-bottom: 10px;



    Here is what I want: (the cards will be only in the red squer.)



    enter image description here



    Questions:



    1. How to fix this and why its working great when I remove the angular2 components and replace them with some simple html text?


    2. Can I summerise this code without effecting anything:



      <div id="categoriesContainer"
      style="width: 15%;border-style: solid;border-width: 1px;border-color: blue;float: left">
      <categories (onCategoryChanged)="categoryChanged($event)"></categories>




    to:



    <categories id="categoriesContainer"
    style="width: 15%;border-style: solid;border-width: 1px;border-color: blue;float: left"
    (onCategoryChanged)="categoryChanged($event)"></categories>


    Thanks alot!










    share|improve this question


























      1












      1








      1








      I have seen some solutions to this problem but when I add inside the divs an angular2 component, it doesn't work.



      Here is what I got so far:
      enter image description here



      Code:



      <div id="container">
      <div id="categoriesContainer">
      <categories (onCategoryChanged)="categoryChanged($event)"></categories>
      </div>
      <div id="products-container">
      <product-details *ngFor="let product of products$ | async" id="prodcut"
      [product]="product"
      [canAddProductToCart]="canAddToCart(product.$key) | async"
      (onAddToCart)="addToCart($event)"></product-details>
      <button md-button
      *ngIf="!showCreateProductComponent"
      id="create-product-button"
      [disabled]="disableCreateProductButton$ |async"
      (click)="showCreateProductComponent=true">
      <i class="material-icons">add</i>
      </button>
      <create-product id="create-product"
      (onCencel)="showCreateProductComponent=false"
      (onCreateProduct)="onCreateProduct($event)"
      *ngIf="showCreateProductComponent"></create-product>
      </div>
      <div style="clear: both"></div>
      </div>


      css:



      //spliting the div to 2 columns
      #container

      border-style:solid;
      border-width: 1px;
      border-color: green;
      padding: 10px;
      margin: 10px

      #categoriesContainer

      width: 15%;
      border-style: solid;
      border-width: 1px;
      border-color: blue;
      float: left;

      #products-container

      border-style: solid;
      border-width: 1px;
      width: 85%;
      border-color: red;


      //for the angular2 compoennts
      #prodcut

      float: left;
      margin-right: 10px;
      margin-bottom: 10px;

      #create-product

      float: left;
      margin-right: 10px;
      margin-bottom: 10px;

      #create-product-button

      float: left;
      margin-right: 10px;
      margin-bottom: 10px;



      Here is what I want: (the cards will be only in the red squer.)



      enter image description here



      Questions:



      1. How to fix this and why its working great when I remove the angular2 components and replace them with some simple html text?


      2. Can I summerise this code without effecting anything:



        <div id="categoriesContainer"
        style="width: 15%;border-style: solid;border-width: 1px;border-color: blue;float: left">
        <categories (onCategoryChanged)="categoryChanged($event)"></categories>




      to:



      <categories id="categoriesContainer"
      style="width: 15%;border-style: solid;border-width: 1px;border-color: blue;float: left"
      (onCategoryChanged)="categoryChanged($event)"></categories>


      Thanks alot!










      share|improve this question
















      I have seen some solutions to this problem but when I add inside the divs an angular2 component, it doesn't work.



      Here is what I got so far:
      enter image description here



      Code:



      <div id="container">
      <div id="categoriesContainer">
      <categories (onCategoryChanged)="categoryChanged($event)"></categories>
      </div>
      <div id="products-container">
      <product-details *ngFor="let product of products$ | async" id="prodcut"
      [product]="product"
      [canAddProductToCart]="canAddToCart(product.$key) | async"
      (onAddToCart)="addToCart($event)"></product-details>
      <button md-button
      *ngIf="!showCreateProductComponent"
      id="create-product-button"
      [disabled]="disableCreateProductButton$ |async"
      (click)="showCreateProductComponent=true">
      <i class="material-icons">add</i>
      </button>
      <create-product id="create-product"
      (onCencel)="showCreateProductComponent=false"
      (onCreateProduct)="onCreateProduct($event)"
      *ngIf="showCreateProductComponent"></create-product>
      </div>
      <div style="clear: both"></div>
      </div>


      css:



      //spliting the div to 2 columns
      #container

      border-style:solid;
      border-width: 1px;
      border-color: green;
      padding: 10px;
      margin: 10px

      #categoriesContainer

      width: 15%;
      border-style: solid;
      border-width: 1px;
      border-color: blue;
      float: left;

      #products-container

      border-style: solid;
      border-width: 1px;
      width: 85%;
      border-color: red;


      //for the angular2 compoennts
      #prodcut

      float: left;
      margin-right: 10px;
      margin-bottom: 10px;

      #create-product

      float: left;
      margin-right: 10px;
      margin-bottom: 10px;

      #create-product-button

      float: left;
      margin-right: 10px;
      margin-bottom: 10px;



      Here is what I want: (the cards will be only in the red squer.)



      enter image description here



      Questions:



      1. How to fix this and why its working great when I remove the angular2 components and replace them with some simple html text?


      2. Can I summerise this code without effecting anything:



        <div id="categoriesContainer"
        style="width: 15%;border-style: solid;border-width: 1px;border-color: blue;float: left">
        <categories (onCategoryChanged)="categoryChanged($event)"></categories>




      to:



      <categories id="categoriesContainer"
      style="width: 15%;border-style: solid;border-width: 1px;border-color: blue;float: left"
      (onCategoryChanged)="categoryChanged($event)"></categories>


      Thanks alot!







      javascript css angular






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 5:10









      Cœur

      17.5k9104145




      17.5k9104145










      asked Oct 26 '16 at 7:45









      Stav AlfiStav Alfi

      3,98674084




      3,98674084






















          2 Answers
          2






          active

          oldest

          votes


















          2














          Simple using flexbox






          *box-sizing:border-box;

          #wrapper
          display: flex;


          #left, #right
          padding: 16px;


          #left
          width: 15%;
          background: red;


          #right
          width: 85%;
          background: blue;

          <div id="wrapper">
          <div id="left">left</div>
          <div id="right">right</div>
          </div>





          Simple using floats and box-sizing



          You might want to use also a .clearfix class here on the parent element






          *box-sizing:border-box;

          #left, #right
          float: left;
          padding: 16px;


          #left
          width: 15%;
          background: red;


          #right
          width: 85%;
          background: blue;

          <div id="wrapper">
          <div id="left">left</div>
          <div id="right">right</div>
          </div>





          Using display:table (cross-browser)






          #wrapper 
          display: table;
          width: 100%;
          border-collapse: collapse;


          #left, #right
          display: table-cell;
          padding: 16px;


          #left
          width: 15%;
          background: red;


          #right
          background: blue;

          <div id="wrapper">
          <div id="left">left</div>
          <div id="right">right</div>
          </div>








          share|improve this answer
































            -1














            Have you tried float:left for children node and clear:both, content: '' for the parent node?



            What I mean is that you miss a float:left for the #products-container



            <div class="container clearfix"> 
            <div id="categoriesContainer" style="float:left" ></div>
            <div id="products-container" style="float:left" ></div>
            </div>


            About the clearfix class, you can refer to Bootstrap here.






            share|improve this answer

























            • Math bro, math. 15% + 85% + paddings + borders != 100%

              – Roko C. Buljan
              Oct 26 '16 at 7:52











            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%2f40256495%2fdividing-div-to-2-columns%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            Simple using flexbox






            *box-sizing:border-box;

            #wrapper
            display: flex;


            #left, #right
            padding: 16px;


            #left
            width: 15%;
            background: red;


            #right
            width: 85%;
            background: blue;

            <div id="wrapper">
            <div id="left">left</div>
            <div id="right">right</div>
            </div>





            Simple using floats and box-sizing



            You might want to use also a .clearfix class here on the parent element






            *box-sizing:border-box;

            #left, #right
            float: left;
            padding: 16px;


            #left
            width: 15%;
            background: red;


            #right
            width: 85%;
            background: blue;

            <div id="wrapper">
            <div id="left">left</div>
            <div id="right">right</div>
            </div>





            Using display:table (cross-browser)






            #wrapper 
            display: table;
            width: 100%;
            border-collapse: collapse;


            #left, #right
            display: table-cell;
            padding: 16px;


            #left
            width: 15%;
            background: red;


            #right
            background: blue;

            <div id="wrapper">
            <div id="left">left</div>
            <div id="right">right</div>
            </div>








            share|improve this answer





























              2














              Simple using flexbox






              *box-sizing:border-box;

              #wrapper
              display: flex;


              #left, #right
              padding: 16px;


              #left
              width: 15%;
              background: red;


              #right
              width: 85%;
              background: blue;

              <div id="wrapper">
              <div id="left">left</div>
              <div id="right">right</div>
              </div>





              Simple using floats and box-sizing



              You might want to use also a .clearfix class here on the parent element






              *box-sizing:border-box;

              #left, #right
              float: left;
              padding: 16px;


              #left
              width: 15%;
              background: red;


              #right
              width: 85%;
              background: blue;

              <div id="wrapper">
              <div id="left">left</div>
              <div id="right">right</div>
              </div>





              Using display:table (cross-browser)






              #wrapper 
              display: table;
              width: 100%;
              border-collapse: collapse;


              #left, #right
              display: table-cell;
              padding: 16px;


              #left
              width: 15%;
              background: red;


              #right
              background: blue;

              <div id="wrapper">
              <div id="left">left</div>
              <div id="right">right</div>
              </div>








              share|improve this answer



























                2












                2








                2







                Simple using flexbox






                *box-sizing:border-box;

                #wrapper
                display: flex;


                #left, #right
                padding: 16px;


                #left
                width: 15%;
                background: red;


                #right
                width: 85%;
                background: blue;

                <div id="wrapper">
                <div id="left">left</div>
                <div id="right">right</div>
                </div>





                Simple using floats and box-sizing



                You might want to use also a .clearfix class here on the parent element






                *box-sizing:border-box;

                #left, #right
                float: left;
                padding: 16px;


                #left
                width: 15%;
                background: red;


                #right
                width: 85%;
                background: blue;

                <div id="wrapper">
                <div id="left">left</div>
                <div id="right">right</div>
                </div>





                Using display:table (cross-browser)






                #wrapper 
                display: table;
                width: 100%;
                border-collapse: collapse;


                #left, #right
                display: table-cell;
                padding: 16px;


                #left
                width: 15%;
                background: red;


                #right
                background: blue;

                <div id="wrapper">
                <div id="left">left</div>
                <div id="right">right</div>
                </div>








                share|improve this answer















                Simple using flexbox






                *box-sizing:border-box;

                #wrapper
                display: flex;


                #left, #right
                padding: 16px;


                #left
                width: 15%;
                background: red;


                #right
                width: 85%;
                background: blue;

                <div id="wrapper">
                <div id="left">left</div>
                <div id="right">right</div>
                </div>





                Simple using floats and box-sizing



                You might want to use also a .clearfix class here on the parent element






                *box-sizing:border-box;

                #left, #right
                float: left;
                padding: 16px;


                #left
                width: 15%;
                background: red;


                #right
                width: 85%;
                background: blue;

                <div id="wrapper">
                <div id="left">left</div>
                <div id="right">right</div>
                </div>





                Using display:table (cross-browser)






                #wrapper 
                display: table;
                width: 100%;
                border-collapse: collapse;


                #left, #right
                display: table-cell;
                padding: 16px;


                #left
                width: 15%;
                background: red;


                #right
                background: blue;

                <div id="wrapper">
                <div id="left">left</div>
                <div id="right">right</div>
                </div>








                *box-sizing:border-box;

                #wrapper
                display: flex;


                #left, #right
                padding: 16px;


                #left
                width: 15%;
                background: red;


                #right
                width: 85%;
                background: blue;

                <div id="wrapper">
                <div id="left">left</div>
                <div id="right">right</div>
                </div>





                *box-sizing:border-box;

                #wrapper
                display: flex;


                #left, #right
                padding: 16px;


                #left
                width: 15%;
                background: red;


                #right
                width: 85%;
                background: blue;

                <div id="wrapper">
                <div id="left">left</div>
                <div id="right">right</div>
                </div>





                *box-sizing:border-box;

                #left, #right
                float: left;
                padding: 16px;


                #left
                width: 15%;
                background: red;


                #right
                width: 85%;
                background: blue;

                <div id="wrapper">
                <div id="left">left</div>
                <div id="right">right</div>
                </div>





                *box-sizing:border-box;

                #left, #right
                float: left;
                padding: 16px;


                #left
                width: 15%;
                background: red;


                #right
                width: 85%;
                background: blue;

                <div id="wrapper">
                <div id="left">left</div>
                <div id="right">right</div>
                </div>





                #wrapper 
                display: table;
                width: 100%;
                border-collapse: collapse;


                #left, #right
                display: table-cell;
                padding: 16px;


                #left
                width: 15%;
                background: red;


                #right
                background: blue;

                <div id="wrapper">
                <div id="left">left</div>
                <div id="right">right</div>
                </div>





                #wrapper 
                display: table;
                width: 100%;
                border-collapse: collapse;


                #left, #right
                display: table-cell;
                padding: 16px;


                #left
                width: 15%;
                background: red;


                #right
                background: blue;

                <div id="wrapper">
                <div id="left">left</div>
                <div id="right">right</div>
                </div>






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Oct 26 '16 at 8:23

























                answered Oct 26 '16 at 8:04









                Roko C. BuljanRoko C. Buljan

                125k21188224




                125k21188224























                    -1














                    Have you tried float:left for children node and clear:both, content: '' for the parent node?



                    What I mean is that you miss a float:left for the #products-container



                    <div class="container clearfix"> 
                    <div id="categoriesContainer" style="float:left" ></div>
                    <div id="products-container" style="float:left" ></div>
                    </div>


                    About the clearfix class, you can refer to Bootstrap here.






                    share|improve this answer

























                    • Math bro, math. 15% + 85% + paddings + borders != 100%

                      – Roko C. Buljan
                      Oct 26 '16 at 7:52
















                    -1














                    Have you tried float:left for children node and clear:both, content: '' for the parent node?



                    What I mean is that you miss a float:left for the #products-container



                    <div class="container clearfix"> 
                    <div id="categoriesContainer" style="float:left" ></div>
                    <div id="products-container" style="float:left" ></div>
                    </div>


                    About the clearfix class, you can refer to Bootstrap here.






                    share|improve this answer

























                    • Math bro, math. 15% + 85% + paddings + borders != 100%

                      – Roko C. Buljan
                      Oct 26 '16 at 7:52














                    -1












                    -1








                    -1







                    Have you tried float:left for children node and clear:both, content: '' for the parent node?



                    What I mean is that you miss a float:left for the #products-container



                    <div class="container clearfix"> 
                    <div id="categoriesContainer" style="float:left" ></div>
                    <div id="products-container" style="float:left" ></div>
                    </div>


                    About the clearfix class, you can refer to Bootstrap here.






                    share|improve this answer















                    Have you tried float:left for children node and clear:both, content: '' for the parent node?



                    What I mean is that you miss a float:left for the #products-container



                    <div class="container clearfix"> 
                    <div id="categoriesContainer" style="float:left" ></div>
                    <div id="products-container" style="float:left" ></div>
                    </div>


                    About the clearfix class, you can refer to Bootstrap here.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Oct 26 '16 at 7:56

























                    answered Oct 26 '16 at 7:51









                    Gabriel CheungGabriel Cheung

                    30226




                    30226












                    • Math bro, math. 15% + 85% + paddings + borders != 100%

                      – Roko C. Buljan
                      Oct 26 '16 at 7:52


















                    • Math bro, math. 15% + 85% + paddings + borders != 100%

                      – Roko C. Buljan
                      Oct 26 '16 at 7:52

















                    Math bro, math. 15% + 85% + paddings + borders != 100%

                    – Roko C. Buljan
                    Oct 26 '16 at 7:52






                    Math bro, math. 15% + 85% + paddings + borders != 100%

                    – Roko C. Buljan
                    Oct 26 '16 at 7:52


















                    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%2f40256495%2fdividing-div-to-2-columns%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







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                    Museum of Modern and Contemporary Art of Trento and Rovereto