Flexbox in responsive table layout: Column not stretching to full height












1















I am using flexbox to create a responsive table. I'd like to achieve the following layout:



Mobile:



X | 1 | 2 |
A | | |
B | | |
C | | |


Desktop:



 X | A | B | C |
1 | | | |
2 | | | |


To this end I have created multiple flexboxes, one as a parent to the entire business and one for each row on the mobile layout.



I have then used breakpoints and flex-direction: row/column, which appears to work pretty well save for one issue:



On the Desktop variant, the X | 1 | 2 column (see style tickets__row) does not stretch to the full height of the parent. This is not what I expected, since align-items: stretch is the default property (plus assigning it has no effect).



How can I solve this? Demo code:






* {
box-sizing: border-box;
}

.tickets__table {
display: flex;
flex-direction: column;
}

.tickets__row {
display: flex;
flex: 1 1 auto;
flex-direction: row;
}

.tickets__cell {
width: 33%;
}

.tickets-label {
border: 1px solid rebeccapurple;
}

.tickets-content {
border: 1px solid aqua;
}

@media all and (min-width:600px) {
.tickets__table {
flex-direction: row;
}

.tickets__row {
flex-direction: column;
}

.tickets__cell {
width: 100%;
}
}

<div class="tickets__table">

<div class="tickets__row">
<div class="tickets__cell tickets-label">
&nbsp;
</div>
<div class="tickets__cell tickets-label">
Price 1
</div>
<div class="tickets__cell tickets-label">
Price 2
</div>
</div>

<div class="tickets__row">
<div class="tickets__cell tickets-label">
Ticket A
</div>
<div class="tickets__cell tickets-content">
$495<br />
<s>$595</s>
</div>
<div class="tickets__cell tickets-content">
$595<br />
<s>$695</s>
</div>
</div>

<div class="tickets__row">
<div class="tickets__cell tickets-label">
Ticket B
</div>
<div class="tickets__cell tickets-content">
$545<br />
<s>$655</s>
</div>
<div class="tickets__cell tickets-content">
$655<br />
<s>$765</s>
</div>
</div>

<div class="tickets__row">
<div class="tickets__cell tickets-label">
Ticket C
</div>
<div class="tickets__cell tickets-content">
$425<br />
<s>$505</s>
</div>
<div class="tickets__cell tickets-content">
$505<br />
<s>$590</s>
</div>
</div>

</div>












share|improve this question





























    1















    I am using flexbox to create a responsive table. I'd like to achieve the following layout:



    Mobile:



    X | 1 | 2 |
    A | | |
    B | | |
    C | | |


    Desktop:



     X | A | B | C |
    1 | | | |
    2 | | | |


    To this end I have created multiple flexboxes, one as a parent to the entire business and one for each row on the mobile layout.



    I have then used breakpoints and flex-direction: row/column, which appears to work pretty well save for one issue:



    On the Desktop variant, the X | 1 | 2 column (see style tickets__row) does not stretch to the full height of the parent. This is not what I expected, since align-items: stretch is the default property (plus assigning it has no effect).



    How can I solve this? Demo code:






    * {
    box-sizing: border-box;
    }

    .tickets__table {
    display: flex;
    flex-direction: column;
    }

    .tickets__row {
    display: flex;
    flex: 1 1 auto;
    flex-direction: row;
    }

    .tickets__cell {
    width: 33%;
    }

    .tickets-label {
    border: 1px solid rebeccapurple;
    }

    .tickets-content {
    border: 1px solid aqua;
    }

    @media all and (min-width:600px) {
    .tickets__table {
    flex-direction: row;
    }

    .tickets__row {
    flex-direction: column;
    }

    .tickets__cell {
    width: 100%;
    }
    }

    <div class="tickets__table">

    <div class="tickets__row">
    <div class="tickets__cell tickets-label">
    &nbsp;
    </div>
    <div class="tickets__cell tickets-label">
    Price 1
    </div>
    <div class="tickets__cell tickets-label">
    Price 2
    </div>
    </div>

    <div class="tickets__row">
    <div class="tickets__cell tickets-label">
    Ticket A
    </div>
    <div class="tickets__cell tickets-content">
    $495<br />
    <s>$595</s>
    </div>
    <div class="tickets__cell tickets-content">
    $595<br />
    <s>$695</s>
    </div>
    </div>

    <div class="tickets__row">
    <div class="tickets__cell tickets-label">
    Ticket B
    </div>
    <div class="tickets__cell tickets-content">
    $545<br />
    <s>$655</s>
    </div>
    <div class="tickets__cell tickets-content">
    $655<br />
    <s>$765</s>
    </div>
    </div>

    <div class="tickets__row">
    <div class="tickets__cell tickets-label">
    Ticket C
    </div>
    <div class="tickets__cell tickets-content">
    $425<br />
    <s>$505</s>
    </div>
    <div class="tickets__cell tickets-content">
    $505<br />
    <s>$590</s>
    </div>
    </div>

    </div>












    share|improve this question



























      1












      1








      1








      I am using flexbox to create a responsive table. I'd like to achieve the following layout:



      Mobile:



      X | 1 | 2 |
      A | | |
      B | | |
      C | | |


      Desktop:



       X | A | B | C |
      1 | | | |
      2 | | | |


      To this end I have created multiple flexboxes, one as a parent to the entire business and one for each row on the mobile layout.



      I have then used breakpoints and flex-direction: row/column, which appears to work pretty well save for one issue:



      On the Desktop variant, the X | 1 | 2 column (see style tickets__row) does not stretch to the full height of the parent. This is not what I expected, since align-items: stretch is the default property (plus assigning it has no effect).



      How can I solve this? Demo code:






      * {
      box-sizing: border-box;
      }

      .tickets__table {
      display: flex;
      flex-direction: column;
      }

      .tickets__row {
      display: flex;
      flex: 1 1 auto;
      flex-direction: row;
      }

      .tickets__cell {
      width: 33%;
      }

      .tickets-label {
      border: 1px solid rebeccapurple;
      }

      .tickets-content {
      border: 1px solid aqua;
      }

      @media all and (min-width:600px) {
      .tickets__table {
      flex-direction: row;
      }

      .tickets__row {
      flex-direction: column;
      }

      .tickets__cell {
      width: 100%;
      }
      }

      <div class="tickets__table">

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      &nbsp;
      </div>
      <div class="tickets__cell tickets-label">
      Price 1
      </div>
      <div class="tickets__cell tickets-label">
      Price 2
      </div>
      </div>

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      Ticket A
      </div>
      <div class="tickets__cell tickets-content">
      $495<br />
      <s>$595</s>
      </div>
      <div class="tickets__cell tickets-content">
      $595<br />
      <s>$695</s>
      </div>
      </div>

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      Ticket B
      </div>
      <div class="tickets__cell tickets-content">
      $545<br />
      <s>$655</s>
      </div>
      <div class="tickets__cell tickets-content">
      $655<br />
      <s>$765</s>
      </div>
      </div>

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      Ticket C
      </div>
      <div class="tickets__cell tickets-content">
      $425<br />
      <s>$505</s>
      </div>
      <div class="tickets__cell tickets-content">
      $505<br />
      <s>$590</s>
      </div>
      </div>

      </div>












      share|improve this question
















      I am using flexbox to create a responsive table. I'd like to achieve the following layout:



      Mobile:



      X | 1 | 2 |
      A | | |
      B | | |
      C | | |


      Desktop:



       X | A | B | C |
      1 | | | |
      2 | | | |


      To this end I have created multiple flexboxes, one as a parent to the entire business and one for each row on the mobile layout.



      I have then used breakpoints and flex-direction: row/column, which appears to work pretty well save for one issue:



      On the Desktop variant, the X | 1 | 2 column (see style tickets__row) does not stretch to the full height of the parent. This is not what I expected, since align-items: stretch is the default property (plus assigning it has no effect).



      How can I solve this? Demo code:






      * {
      box-sizing: border-box;
      }

      .tickets__table {
      display: flex;
      flex-direction: column;
      }

      .tickets__row {
      display: flex;
      flex: 1 1 auto;
      flex-direction: row;
      }

      .tickets__cell {
      width: 33%;
      }

      .tickets-label {
      border: 1px solid rebeccapurple;
      }

      .tickets-content {
      border: 1px solid aqua;
      }

      @media all and (min-width:600px) {
      .tickets__table {
      flex-direction: row;
      }

      .tickets__row {
      flex-direction: column;
      }

      .tickets__cell {
      width: 100%;
      }
      }

      <div class="tickets__table">

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      &nbsp;
      </div>
      <div class="tickets__cell tickets-label">
      Price 1
      </div>
      <div class="tickets__cell tickets-label">
      Price 2
      </div>
      </div>

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      Ticket A
      </div>
      <div class="tickets__cell tickets-content">
      $495<br />
      <s>$595</s>
      </div>
      <div class="tickets__cell tickets-content">
      $595<br />
      <s>$695</s>
      </div>
      </div>

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      Ticket B
      </div>
      <div class="tickets__cell tickets-content">
      $545<br />
      <s>$655</s>
      </div>
      <div class="tickets__cell tickets-content">
      $655<br />
      <s>$765</s>
      </div>
      </div>

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      Ticket C
      </div>
      <div class="tickets__cell tickets-content">
      $425<br />
      <s>$505</s>
      </div>
      <div class="tickets__cell tickets-content">
      $505<br />
      <s>$590</s>
      </div>
      </div>

      </div>








      * {
      box-sizing: border-box;
      }

      .tickets__table {
      display: flex;
      flex-direction: column;
      }

      .tickets__row {
      display: flex;
      flex: 1 1 auto;
      flex-direction: row;
      }

      .tickets__cell {
      width: 33%;
      }

      .tickets-label {
      border: 1px solid rebeccapurple;
      }

      .tickets-content {
      border: 1px solid aqua;
      }

      @media all and (min-width:600px) {
      .tickets__table {
      flex-direction: row;
      }

      .tickets__row {
      flex-direction: column;
      }

      .tickets__cell {
      width: 100%;
      }
      }

      <div class="tickets__table">

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      &nbsp;
      </div>
      <div class="tickets__cell tickets-label">
      Price 1
      </div>
      <div class="tickets__cell tickets-label">
      Price 2
      </div>
      </div>

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      Ticket A
      </div>
      <div class="tickets__cell tickets-content">
      $495<br />
      <s>$595</s>
      </div>
      <div class="tickets__cell tickets-content">
      $595<br />
      <s>$695</s>
      </div>
      </div>

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      Ticket B
      </div>
      <div class="tickets__cell tickets-content">
      $545<br />
      <s>$655</s>
      </div>
      <div class="tickets__cell tickets-content">
      $655<br />
      <s>$765</s>
      </div>
      </div>

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      Ticket C
      </div>
      <div class="tickets__cell tickets-content">
      $425<br />
      <s>$505</s>
      </div>
      <div class="tickets__cell tickets-content">
      $505<br />
      <s>$590</s>
      </div>
      </div>

      </div>





      * {
      box-sizing: border-box;
      }

      .tickets__table {
      display: flex;
      flex-direction: column;
      }

      .tickets__row {
      display: flex;
      flex: 1 1 auto;
      flex-direction: row;
      }

      .tickets__cell {
      width: 33%;
      }

      .tickets-label {
      border: 1px solid rebeccapurple;
      }

      .tickets-content {
      border: 1px solid aqua;
      }

      @media all and (min-width:600px) {
      .tickets__table {
      flex-direction: row;
      }

      .tickets__row {
      flex-direction: column;
      }

      .tickets__cell {
      width: 100%;
      }
      }

      <div class="tickets__table">

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      &nbsp;
      </div>
      <div class="tickets__cell tickets-label">
      Price 1
      </div>
      <div class="tickets__cell tickets-label">
      Price 2
      </div>
      </div>

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      Ticket A
      </div>
      <div class="tickets__cell tickets-content">
      $495<br />
      <s>$595</s>
      </div>
      <div class="tickets__cell tickets-content">
      $595<br />
      <s>$695</s>
      </div>
      </div>

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      Ticket B
      </div>
      <div class="tickets__cell tickets-content">
      $545<br />
      <s>$655</s>
      </div>
      <div class="tickets__cell tickets-content">
      $655<br />
      <s>$765</s>
      </div>
      </div>

      <div class="tickets__row">
      <div class="tickets__cell tickets-label">
      Ticket C
      </div>
      <div class="tickets__cell tickets-content">
      $425<br />
      <s>$505</s>
      </div>
      <div class="tickets__cell tickets-content">
      $505<br />
      <s>$590</s>
      </div>
      </div>

      </div>






      html css css3 flexbox






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 '18 at 0:40









      Temani Afif

      70.9k93877




      70.9k93877










      asked Nov 20 '18 at 0:15









      FrishFrish

      804313




      804313
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You simply need to adjust flex-grow like this:



          .tickets__cell:not(:first-child) {
          flex-grow:1;
          }


          Full code:






          * {
          box-sizing: border-box;
          }

          .tickets__table {
          display: flex;
          flex-direction: column;
          }

          .tickets__row {
          display: flex;
          flex: 1 1 auto;
          flex-direction: row;
          }

          .tickets__cell {
          width: 33%;
          }

          .tickets-label {
          border: 1px solid rebeccapurple;
          }

          .tickets-content {
          border: 1px solid aqua;
          }

          @media all and (min-width:600px) {
          .tickets__table {
          flex-direction: row;
          }
          .tickets__cell:not(:first-child) {
          flex-grow: 1;
          }
          .tickets__row {
          flex-direction: column;
          }
          .tickets__cell {
          width: 100%;
          }
          }

          <div class="tickets__table">

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          &nbsp;
          </div>
          <div class="tickets__cell tickets-label">
          Price 1
          </div>
          <div class="tickets__cell tickets-label">
          Price 2
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket A
          </div>
          <div class="tickets__cell tickets-content">
          $495<br />
          <s>$595</s>
          </div>
          <div class="tickets__cell tickets-content">
          $595<br />
          <s>$695</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket B
          </div>
          <div class="tickets__cell tickets-content">
          $545<br />
          <s>$655</s>
          </div>
          <div class="tickets__cell tickets-content">
          $655<br />
          <s>$765</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket C
          </div>
          <div class="tickets__cell tickets-content">
          $425<br />
          <s>$505</s>
          </div>
          <div class="tickets__cell tickets-content">
          $505<br />
          <s>$590</s>
          </div>
          </div>

          </div>





          As as side note the default value of justify-content is flex-startref and there is no stretch value for it. We have the flex-grow propety to deal with spacing on main axis. stretch is only available for align-items that control the cross axis.





          The MDN page (https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content) is somehow missleading because we ca find stretch as a potential value for justify-content which is correct but there is a missing information that we can only find in the specification of a working draft:




          The justify-content property applies along the main axis, but since stretching in the main axis is controlled by flex, stretch behaves as flex-start.




          So using stretch value within a flexbox container will fallback to flex-start






          share|improve this answer


























          • I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)

            – Frish
            Nov 20 '18 at 0:25











          • Thanks for the info, I have edited out justify-content: stretch from the question (it was bugging me)

            – Frish
            Nov 20 '18 at 0:30








          • 1





            @Frish I added more info about this because it's confusing a lot of people

            – Temani Afif
            Nov 20 '18 at 0:39













          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%2f53384461%2fflexbox-in-responsive-table-layout-column-not-stretching-to-full-height%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You simply need to adjust flex-grow like this:



          .tickets__cell:not(:first-child) {
          flex-grow:1;
          }


          Full code:






          * {
          box-sizing: border-box;
          }

          .tickets__table {
          display: flex;
          flex-direction: column;
          }

          .tickets__row {
          display: flex;
          flex: 1 1 auto;
          flex-direction: row;
          }

          .tickets__cell {
          width: 33%;
          }

          .tickets-label {
          border: 1px solid rebeccapurple;
          }

          .tickets-content {
          border: 1px solid aqua;
          }

          @media all and (min-width:600px) {
          .tickets__table {
          flex-direction: row;
          }
          .tickets__cell:not(:first-child) {
          flex-grow: 1;
          }
          .tickets__row {
          flex-direction: column;
          }
          .tickets__cell {
          width: 100%;
          }
          }

          <div class="tickets__table">

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          &nbsp;
          </div>
          <div class="tickets__cell tickets-label">
          Price 1
          </div>
          <div class="tickets__cell tickets-label">
          Price 2
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket A
          </div>
          <div class="tickets__cell tickets-content">
          $495<br />
          <s>$595</s>
          </div>
          <div class="tickets__cell tickets-content">
          $595<br />
          <s>$695</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket B
          </div>
          <div class="tickets__cell tickets-content">
          $545<br />
          <s>$655</s>
          </div>
          <div class="tickets__cell tickets-content">
          $655<br />
          <s>$765</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket C
          </div>
          <div class="tickets__cell tickets-content">
          $425<br />
          <s>$505</s>
          </div>
          <div class="tickets__cell tickets-content">
          $505<br />
          <s>$590</s>
          </div>
          </div>

          </div>





          As as side note the default value of justify-content is flex-startref and there is no stretch value for it. We have the flex-grow propety to deal with spacing on main axis. stretch is only available for align-items that control the cross axis.





          The MDN page (https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content) is somehow missleading because we ca find stretch as a potential value for justify-content which is correct but there is a missing information that we can only find in the specification of a working draft:




          The justify-content property applies along the main axis, but since stretching in the main axis is controlled by flex, stretch behaves as flex-start.




          So using stretch value within a flexbox container will fallback to flex-start






          share|improve this answer


























          • I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)

            – Frish
            Nov 20 '18 at 0:25











          • Thanks for the info, I have edited out justify-content: stretch from the question (it was bugging me)

            – Frish
            Nov 20 '18 at 0:30








          • 1





            @Frish I added more info about this because it's confusing a lot of people

            – Temani Afif
            Nov 20 '18 at 0:39


















          1














          You simply need to adjust flex-grow like this:



          .tickets__cell:not(:first-child) {
          flex-grow:1;
          }


          Full code:






          * {
          box-sizing: border-box;
          }

          .tickets__table {
          display: flex;
          flex-direction: column;
          }

          .tickets__row {
          display: flex;
          flex: 1 1 auto;
          flex-direction: row;
          }

          .tickets__cell {
          width: 33%;
          }

          .tickets-label {
          border: 1px solid rebeccapurple;
          }

          .tickets-content {
          border: 1px solid aqua;
          }

          @media all and (min-width:600px) {
          .tickets__table {
          flex-direction: row;
          }
          .tickets__cell:not(:first-child) {
          flex-grow: 1;
          }
          .tickets__row {
          flex-direction: column;
          }
          .tickets__cell {
          width: 100%;
          }
          }

          <div class="tickets__table">

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          &nbsp;
          </div>
          <div class="tickets__cell tickets-label">
          Price 1
          </div>
          <div class="tickets__cell tickets-label">
          Price 2
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket A
          </div>
          <div class="tickets__cell tickets-content">
          $495<br />
          <s>$595</s>
          </div>
          <div class="tickets__cell tickets-content">
          $595<br />
          <s>$695</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket B
          </div>
          <div class="tickets__cell tickets-content">
          $545<br />
          <s>$655</s>
          </div>
          <div class="tickets__cell tickets-content">
          $655<br />
          <s>$765</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket C
          </div>
          <div class="tickets__cell tickets-content">
          $425<br />
          <s>$505</s>
          </div>
          <div class="tickets__cell tickets-content">
          $505<br />
          <s>$590</s>
          </div>
          </div>

          </div>





          As as side note the default value of justify-content is flex-startref and there is no stretch value for it. We have the flex-grow propety to deal with spacing on main axis. stretch is only available for align-items that control the cross axis.





          The MDN page (https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content) is somehow missleading because we ca find stretch as a potential value for justify-content which is correct but there is a missing information that we can only find in the specification of a working draft:




          The justify-content property applies along the main axis, but since stretching in the main axis is controlled by flex, stretch behaves as flex-start.




          So using stretch value within a flexbox container will fallback to flex-start






          share|improve this answer


























          • I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)

            – Frish
            Nov 20 '18 at 0:25











          • Thanks for the info, I have edited out justify-content: stretch from the question (it was bugging me)

            – Frish
            Nov 20 '18 at 0:30








          • 1





            @Frish I added more info about this because it's confusing a lot of people

            – Temani Afif
            Nov 20 '18 at 0:39
















          1












          1








          1







          You simply need to adjust flex-grow like this:



          .tickets__cell:not(:first-child) {
          flex-grow:1;
          }


          Full code:






          * {
          box-sizing: border-box;
          }

          .tickets__table {
          display: flex;
          flex-direction: column;
          }

          .tickets__row {
          display: flex;
          flex: 1 1 auto;
          flex-direction: row;
          }

          .tickets__cell {
          width: 33%;
          }

          .tickets-label {
          border: 1px solid rebeccapurple;
          }

          .tickets-content {
          border: 1px solid aqua;
          }

          @media all and (min-width:600px) {
          .tickets__table {
          flex-direction: row;
          }
          .tickets__cell:not(:first-child) {
          flex-grow: 1;
          }
          .tickets__row {
          flex-direction: column;
          }
          .tickets__cell {
          width: 100%;
          }
          }

          <div class="tickets__table">

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          &nbsp;
          </div>
          <div class="tickets__cell tickets-label">
          Price 1
          </div>
          <div class="tickets__cell tickets-label">
          Price 2
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket A
          </div>
          <div class="tickets__cell tickets-content">
          $495<br />
          <s>$595</s>
          </div>
          <div class="tickets__cell tickets-content">
          $595<br />
          <s>$695</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket B
          </div>
          <div class="tickets__cell tickets-content">
          $545<br />
          <s>$655</s>
          </div>
          <div class="tickets__cell tickets-content">
          $655<br />
          <s>$765</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket C
          </div>
          <div class="tickets__cell tickets-content">
          $425<br />
          <s>$505</s>
          </div>
          <div class="tickets__cell tickets-content">
          $505<br />
          <s>$590</s>
          </div>
          </div>

          </div>





          As as side note the default value of justify-content is flex-startref and there is no stretch value for it. We have the flex-grow propety to deal with spacing on main axis. stretch is only available for align-items that control the cross axis.





          The MDN page (https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content) is somehow missleading because we ca find stretch as a potential value for justify-content which is correct but there is a missing information that we can only find in the specification of a working draft:




          The justify-content property applies along the main axis, but since stretching in the main axis is controlled by flex, stretch behaves as flex-start.




          So using stretch value within a flexbox container will fallback to flex-start






          share|improve this answer















          You simply need to adjust flex-grow like this:



          .tickets__cell:not(:first-child) {
          flex-grow:1;
          }


          Full code:






          * {
          box-sizing: border-box;
          }

          .tickets__table {
          display: flex;
          flex-direction: column;
          }

          .tickets__row {
          display: flex;
          flex: 1 1 auto;
          flex-direction: row;
          }

          .tickets__cell {
          width: 33%;
          }

          .tickets-label {
          border: 1px solid rebeccapurple;
          }

          .tickets-content {
          border: 1px solid aqua;
          }

          @media all and (min-width:600px) {
          .tickets__table {
          flex-direction: row;
          }
          .tickets__cell:not(:first-child) {
          flex-grow: 1;
          }
          .tickets__row {
          flex-direction: column;
          }
          .tickets__cell {
          width: 100%;
          }
          }

          <div class="tickets__table">

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          &nbsp;
          </div>
          <div class="tickets__cell tickets-label">
          Price 1
          </div>
          <div class="tickets__cell tickets-label">
          Price 2
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket A
          </div>
          <div class="tickets__cell tickets-content">
          $495<br />
          <s>$595</s>
          </div>
          <div class="tickets__cell tickets-content">
          $595<br />
          <s>$695</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket B
          </div>
          <div class="tickets__cell tickets-content">
          $545<br />
          <s>$655</s>
          </div>
          <div class="tickets__cell tickets-content">
          $655<br />
          <s>$765</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket C
          </div>
          <div class="tickets__cell tickets-content">
          $425<br />
          <s>$505</s>
          </div>
          <div class="tickets__cell tickets-content">
          $505<br />
          <s>$590</s>
          </div>
          </div>

          </div>





          As as side note the default value of justify-content is flex-startref and there is no stretch value for it. We have the flex-grow propety to deal with spacing on main axis. stretch is only available for align-items that control the cross axis.





          The MDN page (https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content) is somehow missleading because we ca find stretch as a potential value for justify-content which is correct but there is a missing information that we can only find in the specification of a working draft:




          The justify-content property applies along the main axis, but since stretching in the main axis is controlled by flex, stretch behaves as flex-start.




          So using stretch value within a flexbox container will fallback to flex-start






          * {
          box-sizing: border-box;
          }

          .tickets__table {
          display: flex;
          flex-direction: column;
          }

          .tickets__row {
          display: flex;
          flex: 1 1 auto;
          flex-direction: row;
          }

          .tickets__cell {
          width: 33%;
          }

          .tickets-label {
          border: 1px solid rebeccapurple;
          }

          .tickets-content {
          border: 1px solid aqua;
          }

          @media all and (min-width:600px) {
          .tickets__table {
          flex-direction: row;
          }
          .tickets__cell:not(:first-child) {
          flex-grow: 1;
          }
          .tickets__row {
          flex-direction: column;
          }
          .tickets__cell {
          width: 100%;
          }
          }

          <div class="tickets__table">

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          &nbsp;
          </div>
          <div class="tickets__cell tickets-label">
          Price 1
          </div>
          <div class="tickets__cell tickets-label">
          Price 2
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket A
          </div>
          <div class="tickets__cell tickets-content">
          $495<br />
          <s>$595</s>
          </div>
          <div class="tickets__cell tickets-content">
          $595<br />
          <s>$695</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket B
          </div>
          <div class="tickets__cell tickets-content">
          $545<br />
          <s>$655</s>
          </div>
          <div class="tickets__cell tickets-content">
          $655<br />
          <s>$765</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket C
          </div>
          <div class="tickets__cell tickets-content">
          $425<br />
          <s>$505</s>
          </div>
          <div class="tickets__cell tickets-content">
          $505<br />
          <s>$590</s>
          </div>
          </div>

          </div>





          * {
          box-sizing: border-box;
          }

          .tickets__table {
          display: flex;
          flex-direction: column;
          }

          .tickets__row {
          display: flex;
          flex: 1 1 auto;
          flex-direction: row;
          }

          .tickets__cell {
          width: 33%;
          }

          .tickets-label {
          border: 1px solid rebeccapurple;
          }

          .tickets-content {
          border: 1px solid aqua;
          }

          @media all and (min-width:600px) {
          .tickets__table {
          flex-direction: row;
          }
          .tickets__cell:not(:first-child) {
          flex-grow: 1;
          }
          .tickets__row {
          flex-direction: column;
          }
          .tickets__cell {
          width: 100%;
          }
          }

          <div class="tickets__table">

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          &nbsp;
          </div>
          <div class="tickets__cell tickets-label">
          Price 1
          </div>
          <div class="tickets__cell tickets-label">
          Price 2
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket A
          </div>
          <div class="tickets__cell tickets-content">
          $495<br />
          <s>$595</s>
          </div>
          <div class="tickets__cell tickets-content">
          $595<br />
          <s>$695</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket B
          </div>
          <div class="tickets__cell tickets-content">
          $545<br />
          <s>$655</s>
          </div>
          <div class="tickets__cell tickets-content">
          $655<br />
          <s>$765</s>
          </div>
          </div>

          <div class="tickets__row">
          <div class="tickets__cell tickets-label">
          Ticket C
          </div>
          <div class="tickets__cell tickets-content">
          $425<br />
          <s>$505</s>
          </div>
          <div class="tickets__cell tickets-content">
          $505<br />
          <s>$590</s>
          </div>
          </div>

          </div>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 '18 at 0:42

























          answered Nov 20 '18 at 0:23









          Temani AfifTemani Afif

          70.9k93877




          70.9k93877













          • I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)

            – Frish
            Nov 20 '18 at 0:25











          • Thanks for the info, I have edited out justify-content: stretch from the question (it was bugging me)

            – Frish
            Nov 20 '18 at 0:30








          • 1





            @Frish I added more info about this because it's confusing a lot of people

            – Temani Afif
            Nov 20 '18 at 0:39





















          • I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)

            – Frish
            Nov 20 '18 at 0:25











          • Thanks for the info, I have edited out justify-content: stretch from the question (it was bugging me)

            – Frish
            Nov 20 '18 at 0:30








          • 1





            @Frish I added more info about this because it's confusing a lot of people

            – Temani Afif
            Nov 20 '18 at 0:39



















          I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)

          – Frish
          Nov 20 '18 at 0:25





          I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)

          – Frish
          Nov 20 '18 at 0:25













          Thanks for the info, I have edited out justify-content: stretch from the question (it was bugging me)

          – Frish
          Nov 20 '18 at 0:30







          Thanks for the info, I have edited out justify-content: stretch from the question (it was bugging me)

          – Frish
          Nov 20 '18 at 0:30






          1




          1





          @Frish I added more info about this because it's confusing a lot of people

          – Temani Afif
          Nov 20 '18 at 0:39







          @Frish I added more info about this because it's confusing a lot of people

          – Temani Afif
          Nov 20 '18 at 0:39




















          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%2f53384461%2fflexbox-in-responsive-table-layout-column-not-stretching-to-full-height%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents