Flexbox in responsive table layout: Column not stretching to full height
up vote
1
down vote
favorite
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">
</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
add a comment |
up vote
1
down vote
favorite
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">
</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
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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">
</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
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">
</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">
</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">
</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
html css css3 flexbox
edited Nov 20 at 0:40
Temani Afif
61.7k93572
61.7k93572
asked Nov 20 at 0:15
Frish
814313
814313
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
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">
</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-start
ref 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
I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)
– Frish
Nov 20 at 0:25
Thanks for the info, I have edited outjustify-content: stretch
from the question (it was bugging me)
– Frish
Nov 20 at 0:30
1
@Frish I added more info about this because it's confusing a lot of people
– Temani Afif
Nov 20 at 0:39
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
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">
</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-start
ref 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
I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)
– Frish
Nov 20 at 0:25
Thanks for the info, I have edited outjustify-content: stretch
from the question (it was bugging me)
– Frish
Nov 20 at 0:30
1
@Frish I added more info about this because it's confusing a lot of people
– Temani Afif
Nov 20 at 0:39
add a comment |
up vote
1
down vote
accepted
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">
</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-start
ref 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
I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)
– Frish
Nov 20 at 0:25
Thanks for the info, I have edited outjustify-content: stretch
from the question (it was bugging me)
– Frish
Nov 20 at 0:30
1
@Frish I added more info about this because it's confusing a lot of people
– Temani Afif
Nov 20 at 0:39
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
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">
</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-start
ref 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
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">
</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-start
ref 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">
</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">
</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>
edited Nov 20 at 0:42
answered Nov 20 at 0:23
Temani Afif
61.7k93572
61.7k93572
I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)
– Frish
Nov 20 at 0:25
Thanks for the info, I have edited outjustify-content: stretch
from the question (it was bugging me)
– Frish
Nov 20 at 0:30
1
@Frish I added more info about this because it's confusing a lot of people
– Temani Afif
Nov 20 at 0:39
add a comment |
I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)
– Frish
Nov 20 at 0:25
Thanks for the info, I have edited outjustify-content: stretch
from the question (it was bugging me)
– Frish
Nov 20 at 0:30
1
@Frish I added more info about this because it's confusing a lot of people
– Temani Afif
Nov 20 at 0:39
I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)
– Frish
Nov 20 at 0:25
I had a feeling it would be something simple! Thank you @TemaniAfif, much appreciated :)
– Frish
Nov 20 at 0:25
Thanks for the info, I have edited out
justify-content: stretch
from the question (it was bugging me)– Frish
Nov 20 at 0:30
Thanks for the info, I have edited out
justify-content: stretch
from the question (it was bugging me)– Frish
Nov 20 at 0:30
1
1
@Frish I added more info about this because it's confusing a lot of people
– Temani Afif
Nov 20 at 0:39
@Frish I added more info about this because it's confusing a lot of people
– Temani Afif
Nov 20 at 0:39
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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