What are the areas covered by Flexbox which are difficult or impossible to achieve with Grid?Center columns inside Grid LayoutShould I use Flexbox or CSS Grid?How can I have a sticky footer with my CSS Grid layout?Can auto margins work in CSS Grid like they do in Flexbox?Make CSS Grid auto-fill only 2 columnsAligning grid items across the entire row/column (like flex items can)How to get grid items of different lengths to wrap?CSS grid max columns without media queriesSetting the minimum, maximum and default length of a grid column / rowShrink grid items just like flex items in cssHow to specify an element after which to wrap in css flexbox?css grid of squares with flexboxAchieving a certain grid using flexboxCreating a two column layout with flexboxResponsively collapse 2 column layout to single columnWhat is the difference between CSS Flexbox , CSS GridsRecreating a CSS Grid layout with FlexboxSpecialized layout with CSS Grid/FlexboxUnderstanding CSS grid and flexboxFlexbox grid item which uses full width before growing in height
I'm flying to France today and my passport expires in less than 2 months
How can bays and straits be determined in a procedurally generated map?
If human space travel is limited by the G force vulnerability, is there a way to counter G forces?
How is it possible to have an ability score that is less than 3?
Watching something be written to a file live with tail
How much RAM could one put in a typical 80386 setup?
Malcev's paper "On a class of homogeneous spaces" in English
Can I make popcorn with any corn?
Is it possible to run Internet Explorer on OS X El Capitan?
NMaximize is not converging to a solution
Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?
What does it mean to describe someone as a butt steak?
How much of data wrangling is a data scientist's job?
RSA: Danger of using p to create q
Are the number of citations and number of published articles the most important criteria for a tenure promotion?
How to format long polynomial?
Perform and show arithmetic with LuaLaTeX
Can you really stack all of this on an Opportunity Attack?
Cross compiling for RPi - error while loading shared libraries
Paid for article while in US on F-1 visa?
Does detail obscure or enhance action?
LaTeX: Why are digits allowed in environments, but forbidden in commands?
Why does Kotter return in Welcome Back Kotter?
Replacing matching entries in one column of a file by another column from a different file
What are the areas covered by Flexbox which are difficult or impossible to achieve with Grid?
Center columns inside Grid LayoutShould I use Flexbox or CSS Grid?How can I have a sticky footer with my CSS Grid layout?Can auto margins work in CSS Grid like they do in Flexbox?Make CSS Grid auto-fill only 2 columnsAligning grid items across the entire row/column (like flex items can)How to get grid items of different lengths to wrap?CSS grid max columns without media queriesSetting the minimum, maximum and default length of a grid column / rowShrink grid items just like flex items in cssHow to specify an element after which to wrap in css flexbox?css grid of squares with flexboxAchieving a certain grid using flexboxCreating a two column layout with flexboxResponsively collapse 2 column layout to single columnWhat is the difference between CSS Flexbox , CSS GridsRecreating a CSS Grid layout with FlexboxSpecialized layout with CSS Grid/FlexboxUnderstanding CSS grid and flexboxFlexbox grid item which uses full width before growing in height
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
It is wildly highlighted that Flexbox is for 1-D and Grid for 2-D but I have not found a clear explanation why Grid could not be used for 1-D and replace Flexbox. The closest I came to is
But you could also argue that purely 1D layout like this is more
powerful in Flexbox, because Flexbox allows us to move those elements
around easier (e.g. move them all to one side or another, change their
order, space them out evenly, etc).
I use Grid and Flexbox for basic layout: a general placement of the boxes on the page and some dynamic ones, usually stacked. The esthetical ones (toasters, modals, ...) are managed through a framework. I have not yet found a case where Grid could not replace Flexbox out of the box (that is without advanced CSS gymnastics or a lot of code).
To take the example of the quote above, all the "moves" mentioned are directly available in Grid, usually with the same semantics as in Flexbox.
What are the fundamental areas covered by Flexbox which are difficult or impossible to manage with Grid?
EDIT: the browser support is not important (I only use evergreen browsers and can switch if needed)
css flexbox css-grid
add a comment |
It is wildly highlighted that Flexbox is for 1-D and Grid for 2-D but I have not found a clear explanation why Grid could not be used for 1-D and replace Flexbox. The closest I came to is
But you could also argue that purely 1D layout like this is more
powerful in Flexbox, because Flexbox allows us to move those elements
around easier (e.g. move them all to one side or another, change their
order, space them out evenly, etc).
I use Grid and Flexbox for basic layout: a general placement of the boxes on the page and some dynamic ones, usually stacked. The esthetical ones (toasters, modals, ...) are managed through a framework. I have not yet found a case where Grid could not replace Flexbox out of the box (that is without advanced CSS gymnastics or a lot of code).
To take the example of the quote above, all the "moves" mentioned are directly available in Grid, usually with the same semantics as in Flexbox.
What are the fundamental areas covered by Flexbox which are difficult or impossible to manage with Grid?
EDIT: the browser support is not important (I only use evergreen browsers and can switch if needed)
css flexbox css-grid
add a comment |
It is wildly highlighted that Flexbox is for 1-D and Grid for 2-D but I have not found a clear explanation why Grid could not be used for 1-D and replace Flexbox. The closest I came to is
But you could also argue that purely 1D layout like this is more
powerful in Flexbox, because Flexbox allows us to move those elements
around easier (e.g. move them all to one side or another, change their
order, space them out evenly, etc).
I use Grid and Flexbox for basic layout: a general placement of the boxes on the page and some dynamic ones, usually stacked. The esthetical ones (toasters, modals, ...) are managed through a framework. I have not yet found a case where Grid could not replace Flexbox out of the box (that is without advanced CSS gymnastics or a lot of code).
To take the example of the quote above, all the "moves" mentioned are directly available in Grid, usually with the same semantics as in Flexbox.
What are the fundamental areas covered by Flexbox which are difficult or impossible to manage with Grid?
EDIT: the browser support is not important (I only use evergreen browsers and can switch if needed)
css flexbox css-grid
It is wildly highlighted that Flexbox is for 1-D and Grid for 2-D but I have not found a clear explanation why Grid could not be used for 1-D and replace Flexbox. The closest I came to is
But you could also argue that purely 1D layout like this is more
powerful in Flexbox, because Flexbox allows us to move those elements
around easier (e.g. move them all to one side or another, change their
order, space them out evenly, etc).
I use Grid and Flexbox for basic layout: a general placement of the boxes on the page and some dynamic ones, usually stacked. The esthetical ones (toasters, modals, ...) are managed through a framework. I have not yet found a case where Grid could not replace Flexbox out of the box (that is without advanced CSS gymnastics or a lot of code).
To take the example of the quote above, all the "moves" mentioned are directly available in Grid, usually with the same semantics as in Flexbox.
What are the fundamental areas covered by Flexbox which are difficult or impossible to manage with Grid?
EDIT: the browser support is not important (I only use evergreen browsers and can switch if needed)
css flexbox css-grid
css flexbox css-grid
edited Mar 8 at 23:35
Michael_B
158k50255363
158k50255363
asked Mar 8 at 13:43
WoJWoJ
6,8231266146
6,8231266146
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Advantage Flexbox
Here are 9 areas where flexbox comes out ahead of Grid (Level 1):
Centering wrapped items. Imagine five flex items. Only four per row. The fifth one wraps. That fifth one can be easily aligned across the entire row with
justify-content
. Try centering this fifth item in a grid container. Not a simple matter.Aligning grid items across the entire row/column (like flex items can)
Wrapping. Flex items of variable lengths have no problem wrapping. Try getting grid items of variable lengths to wrap. Not possible.
How to get grid items of different lengths to wrap?
Auto margins. Flex items can be placed, packed and spaced away throughout their container with
auto
margins. Grid items, however, are confined to their tracks, greatly diminishing the utility ofauto
margins.Can auto margins work in CSS Grid like they do in Flexbox?
Min, Max, Default – all in one. Setting the
min-width
,max-width
and defaultwidth
of a flex item is easy. How can all three lengths be set on a grid column or row? They can't.Setting the minimum, maximum and default length of a grid column / row
Sticky footer / header. It's just so much simpler and easier to pin a footer or header with flexbox.
How can I have a sticky footer with my CSS Grid layout?
Consuming remaining space. A flex item can consume remaining space with
flex-grow
. Grid items have no such function.Make grid item use remaining space like flex item with flex-grow: 1
Shrinking. Flex has
flex-shrink
. Grid has... nothing.Shrink grid items just like flex items in css
Limiting the column count in a dynamic layout. With flexbox, creating a wrapping two-column grid that remains fixed at two-columns across screen sizes is no problem. In Grid, despite having all these great functions, such
repeat()
,auto-fill
andminmax()
, it can't be done.Make CSS Grid auto-fill only 2 columns
CSS grid max columns without media queries
Creating space between first and last items. In a grid container with a variable number of columns, it's not easy to add an empty first and last column. Margins, padding, columns and pseudo elements each have their limitations. It's simple and easy with flexbox.
Add space before and after first and last grid items
add a comment |
Flexbox and CSS grid are two different features and I don't agree about saying that one can replace another or that CSS grid is a superset of flexbox.
You said:
I have not found a clear explanation why Grid could not be used for 1-D and replace Flexbox.
Here is a basic flexbox example that involve wrapping that you cannot achieve (or probably difficult to achieve) using CSS grid. Reduce the window size and see how the elements will behave.
.box
display: flex;
flex-wrap: wrap;
.box>span
border: 1px solid;
padding: 10px;
flex-grow: 1;
<div class="box">
<span>some text very long here some text very long here </span>
<span>text here</span>
<span>A</span>
<span>B</span>
</div>
This is a 1-D layout where each line may have elements resized differently depending on the free space without being inside a 2-D grid. It will be difficult to achieve the same output using CSS-grid.
Basically flexbox is more suited when it comes to multiline/multirow content following one direction whereas CSS grid is more about a Grid with row and columns. Of course, when it comes to only one line a 2D grid can be considerd as 1D thus flexbox and CSS grid may achieve the same thing.
It's like comparing a table with only one tr
and multiple td
with a set of inline-block
element inside one line BUT when it comes to wrapping and multiple tr
it's clear that table and inline-block
are different.
Worth to note that you can achieve what you want using any techniques in general. In the past, Flexbox wasn't there and developers were able to build layout using float
(Boostrap is the best example). Then flexbox come with more powerful features to make things easier. Same thing for CSS grid and for future features.
Here is an example : https://drafts.csswg.org/css-align-3/
This Draft is talking about a future enhancement of alignment where we can consider jutify-content
, align-items
, etc without even using flexbox or CSS grid but directly on block elements.
If implemented, will this make Flexbox and CSS Grid useless? I don't think so.
add a comment |
I should probably point out that Grid
is MUCH newer than Flexbox
and therefore may actually be intended as a replacement to some extent. Much like Flexbox replaced the typical use case for float
(not the intended use).
I'm going to preface this by saying, I rarely NEED the complexities/capabilities of Grid so I still use Flexbox for most things.
However, in my experience, the flex-wrap
capabilities, especially with variable screen sizes, is one place that I feel Grid isn't a great replacement.
add a comment |
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
);
);
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%2f55064488%2fwhat-are-the-areas-covered-by-flexbox-which-are-difficult-or-impossible-to-achie%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Advantage Flexbox
Here are 9 areas where flexbox comes out ahead of Grid (Level 1):
Centering wrapped items. Imagine five flex items. Only four per row. The fifth one wraps. That fifth one can be easily aligned across the entire row with
justify-content
. Try centering this fifth item in a grid container. Not a simple matter.Aligning grid items across the entire row/column (like flex items can)
Wrapping. Flex items of variable lengths have no problem wrapping. Try getting grid items of variable lengths to wrap. Not possible.
How to get grid items of different lengths to wrap?
Auto margins. Flex items can be placed, packed and spaced away throughout their container with
auto
margins. Grid items, however, are confined to their tracks, greatly diminishing the utility ofauto
margins.Can auto margins work in CSS Grid like they do in Flexbox?
Min, Max, Default – all in one. Setting the
min-width
,max-width
and defaultwidth
of a flex item is easy. How can all three lengths be set on a grid column or row? They can't.Setting the minimum, maximum and default length of a grid column / row
Sticky footer / header. It's just so much simpler and easier to pin a footer or header with flexbox.
How can I have a sticky footer with my CSS Grid layout?
Consuming remaining space. A flex item can consume remaining space with
flex-grow
. Grid items have no such function.Make grid item use remaining space like flex item with flex-grow: 1
Shrinking. Flex has
flex-shrink
. Grid has... nothing.Shrink grid items just like flex items in css
Limiting the column count in a dynamic layout. With flexbox, creating a wrapping two-column grid that remains fixed at two-columns across screen sizes is no problem. In Grid, despite having all these great functions, such
repeat()
,auto-fill
andminmax()
, it can't be done.Make CSS Grid auto-fill only 2 columns
CSS grid max columns without media queries
Creating space between first and last items. In a grid container with a variable number of columns, it's not easy to add an empty first and last column. Margins, padding, columns and pseudo elements each have their limitations. It's simple and easy with flexbox.
Add space before and after first and last grid items
add a comment |
Advantage Flexbox
Here are 9 areas where flexbox comes out ahead of Grid (Level 1):
Centering wrapped items. Imagine five flex items. Only four per row. The fifth one wraps. That fifth one can be easily aligned across the entire row with
justify-content
. Try centering this fifth item in a grid container. Not a simple matter.Aligning grid items across the entire row/column (like flex items can)
Wrapping. Flex items of variable lengths have no problem wrapping. Try getting grid items of variable lengths to wrap. Not possible.
How to get grid items of different lengths to wrap?
Auto margins. Flex items can be placed, packed and spaced away throughout their container with
auto
margins. Grid items, however, are confined to their tracks, greatly diminishing the utility ofauto
margins.Can auto margins work in CSS Grid like they do in Flexbox?
Min, Max, Default – all in one. Setting the
min-width
,max-width
and defaultwidth
of a flex item is easy. How can all three lengths be set on a grid column or row? They can't.Setting the minimum, maximum and default length of a grid column / row
Sticky footer / header. It's just so much simpler and easier to pin a footer or header with flexbox.
How can I have a sticky footer with my CSS Grid layout?
Consuming remaining space. A flex item can consume remaining space with
flex-grow
. Grid items have no such function.Make grid item use remaining space like flex item with flex-grow: 1
Shrinking. Flex has
flex-shrink
. Grid has... nothing.Shrink grid items just like flex items in css
Limiting the column count in a dynamic layout. With flexbox, creating a wrapping two-column grid that remains fixed at two-columns across screen sizes is no problem. In Grid, despite having all these great functions, such
repeat()
,auto-fill
andminmax()
, it can't be done.Make CSS Grid auto-fill only 2 columns
CSS grid max columns without media queries
Creating space between first and last items. In a grid container with a variable number of columns, it's not easy to add an empty first and last column. Margins, padding, columns and pseudo elements each have their limitations. It's simple and easy with flexbox.
Add space before and after first and last grid items
add a comment |
Advantage Flexbox
Here are 9 areas where flexbox comes out ahead of Grid (Level 1):
Centering wrapped items. Imagine five flex items. Only four per row. The fifth one wraps. That fifth one can be easily aligned across the entire row with
justify-content
. Try centering this fifth item in a grid container. Not a simple matter.Aligning grid items across the entire row/column (like flex items can)
Wrapping. Flex items of variable lengths have no problem wrapping. Try getting grid items of variable lengths to wrap. Not possible.
How to get grid items of different lengths to wrap?
Auto margins. Flex items can be placed, packed and spaced away throughout their container with
auto
margins. Grid items, however, are confined to their tracks, greatly diminishing the utility ofauto
margins.Can auto margins work in CSS Grid like they do in Flexbox?
Min, Max, Default – all in one. Setting the
min-width
,max-width
and defaultwidth
of a flex item is easy. How can all three lengths be set on a grid column or row? They can't.Setting the minimum, maximum and default length of a grid column / row
Sticky footer / header. It's just so much simpler and easier to pin a footer or header with flexbox.
How can I have a sticky footer with my CSS Grid layout?
Consuming remaining space. A flex item can consume remaining space with
flex-grow
. Grid items have no such function.Make grid item use remaining space like flex item with flex-grow: 1
Shrinking. Flex has
flex-shrink
. Grid has... nothing.Shrink grid items just like flex items in css
Limiting the column count in a dynamic layout. With flexbox, creating a wrapping two-column grid that remains fixed at two-columns across screen sizes is no problem. In Grid, despite having all these great functions, such
repeat()
,auto-fill
andminmax()
, it can't be done.Make CSS Grid auto-fill only 2 columns
CSS grid max columns without media queries
Creating space between first and last items. In a grid container with a variable number of columns, it's not easy to add an empty first and last column. Margins, padding, columns and pseudo elements each have their limitations. It's simple and easy with flexbox.
Add space before and after first and last grid items
Advantage Flexbox
Here are 9 areas where flexbox comes out ahead of Grid (Level 1):
Centering wrapped items. Imagine five flex items. Only four per row. The fifth one wraps. That fifth one can be easily aligned across the entire row with
justify-content
. Try centering this fifth item in a grid container. Not a simple matter.Aligning grid items across the entire row/column (like flex items can)
Wrapping. Flex items of variable lengths have no problem wrapping. Try getting grid items of variable lengths to wrap. Not possible.
How to get grid items of different lengths to wrap?
Auto margins. Flex items can be placed, packed and spaced away throughout their container with
auto
margins. Grid items, however, are confined to their tracks, greatly diminishing the utility ofauto
margins.Can auto margins work in CSS Grid like they do in Flexbox?
Min, Max, Default – all in one. Setting the
min-width
,max-width
and defaultwidth
of a flex item is easy. How can all three lengths be set on a grid column or row? They can't.Setting the minimum, maximum and default length of a grid column / row
Sticky footer / header. It's just so much simpler and easier to pin a footer or header with flexbox.
How can I have a sticky footer with my CSS Grid layout?
Consuming remaining space. A flex item can consume remaining space with
flex-grow
. Grid items have no such function.Make grid item use remaining space like flex item with flex-grow: 1
Shrinking. Flex has
flex-shrink
. Grid has... nothing.Shrink grid items just like flex items in css
Limiting the column count in a dynamic layout. With flexbox, creating a wrapping two-column grid that remains fixed at two-columns across screen sizes is no problem. In Grid, despite having all these great functions, such
repeat()
,auto-fill
andminmax()
, it can't be done.Make CSS Grid auto-fill only 2 columns
CSS grid max columns without media queries
Creating space between first and last items. In a grid container with a variable number of columns, it's not easy to add an empty first and last column. Margins, padding, columns and pseudo elements each have their limitations. It's simple and easy with flexbox.
Add space before and after first and last grid items
edited Mar 22 at 18:08
answered Mar 9 at 1:12
Michael_BMichael_B
158k50255363
158k50255363
add a comment |
add a comment |
Flexbox and CSS grid are two different features and I don't agree about saying that one can replace another or that CSS grid is a superset of flexbox.
You said:
I have not found a clear explanation why Grid could not be used for 1-D and replace Flexbox.
Here is a basic flexbox example that involve wrapping that you cannot achieve (or probably difficult to achieve) using CSS grid. Reduce the window size and see how the elements will behave.
.box
display: flex;
flex-wrap: wrap;
.box>span
border: 1px solid;
padding: 10px;
flex-grow: 1;
<div class="box">
<span>some text very long here some text very long here </span>
<span>text here</span>
<span>A</span>
<span>B</span>
</div>
This is a 1-D layout where each line may have elements resized differently depending on the free space without being inside a 2-D grid. It will be difficult to achieve the same output using CSS-grid.
Basically flexbox is more suited when it comes to multiline/multirow content following one direction whereas CSS grid is more about a Grid with row and columns. Of course, when it comes to only one line a 2D grid can be considerd as 1D thus flexbox and CSS grid may achieve the same thing.
It's like comparing a table with only one tr
and multiple td
with a set of inline-block
element inside one line BUT when it comes to wrapping and multiple tr
it's clear that table and inline-block
are different.
Worth to note that you can achieve what you want using any techniques in general. In the past, Flexbox wasn't there and developers were able to build layout using float
(Boostrap is the best example). Then flexbox come with more powerful features to make things easier. Same thing for CSS grid and for future features.
Here is an example : https://drafts.csswg.org/css-align-3/
This Draft is talking about a future enhancement of alignment where we can consider jutify-content
, align-items
, etc without even using flexbox or CSS grid but directly on block elements.
If implemented, will this make Flexbox and CSS Grid useless? I don't think so.
add a comment |
Flexbox and CSS grid are two different features and I don't agree about saying that one can replace another or that CSS grid is a superset of flexbox.
You said:
I have not found a clear explanation why Grid could not be used for 1-D and replace Flexbox.
Here is a basic flexbox example that involve wrapping that you cannot achieve (or probably difficult to achieve) using CSS grid. Reduce the window size and see how the elements will behave.
.box
display: flex;
flex-wrap: wrap;
.box>span
border: 1px solid;
padding: 10px;
flex-grow: 1;
<div class="box">
<span>some text very long here some text very long here </span>
<span>text here</span>
<span>A</span>
<span>B</span>
</div>
This is a 1-D layout where each line may have elements resized differently depending on the free space without being inside a 2-D grid. It will be difficult to achieve the same output using CSS-grid.
Basically flexbox is more suited when it comes to multiline/multirow content following one direction whereas CSS grid is more about a Grid with row and columns. Of course, when it comes to only one line a 2D grid can be considerd as 1D thus flexbox and CSS grid may achieve the same thing.
It's like comparing a table with only one tr
and multiple td
with a set of inline-block
element inside one line BUT when it comes to wrapping and multiple tr
it's clear that table and inline-block
are different.
Worth to note that you can achieve what you want using any techniques in general. In the past, Flexbox wasn't there and developers were able to build layout using float
(Boostrap is the best example). Then flexbox come with more powerful features to make things easier. Same thing for CSS grid and for future features.
Here is an example : https://drafts.csswg.org/css-align-3/
This Draft is talking about a future enhancement of alignment where we can consider jutify-content
, align-items
, etc without even using flexbox or CSS grid but directly on block elements.
If implemented, will this make Flexbox and CSS Grid useless? I don't think so.
add a comment |
Flexbox and CSS grid are two different features and I don't agree about saying that one can replace another or that CSS grid is a superset of flexbox.
You said:
I have not found a clear explanation why Grid could not be used for 1-D and replace Flexbox.
Here is a basic flexbox example that involve wrapping that you cannot achieve (or probably difficult to achieve) using CSS grid. Reduce the window size and see how the elements will behave.
.box
display: flex;
flex-wrap: wrap;
.box>span
border: 1px solid;
padding: 10px;
flex-grow: 1;
<div class="box">
<span>some text very long here some text very long here </span>
<span>text here</span>
<span>A</span>
<span>B</span>
</div>
This is a 1-D layout where each line may have elements resized differently depending on the free space without being inside a 2-D grid. It will be difficult to achieve the same output using CSS-grid.
Basically flexbox is more suited when it comes to multiline/multirow content following one direction whereas CSS grid is more about a Grid with row and columns. Of course, when it comes to only one line a 2D grid can be considerd as 1D thus flexbox and CSS grid may achieve the same thing.
It's like comparing a table with only one tr
and multiple td
with a set of inline-block
element inside one line BUT when it comes to wrapping and multiple tr
it's clear that table and inline-block
are different.
Worth to note that you can achieve what you want using any techniques in general. In the past, Flexbox wasn't there and developers were able to build layout using float
(Boostrap is the best example). Then flexbox come with more powerful features to make things easier. Same thing for CSS grid and for future features.
Here is an example : https://drafts.csswg.org/css-align-3/
This Draft is talking about a future enhancement of alignment where we can consider jutify-content
, align-items
, etc without even using flexbox or CSS grid but directly on block elements.
If implemented, will this make Flexbox and CSS Grid useless? I don't think so.
Flexbox and CSS grid are two different features and I don't agree about saying that one can replace another or that CSS grid is a superset of flexbox.
You said:
I have not found a clear explanation why Grid could not be used for 1-D and replace Flexbox.
Here is a basic flexbox example that involve wrapping that you cannot achieve (or probably difficult to achieve) using CSS grid. Reduce the window size and see how the elements will behave.
.box
display: flex;
flex-wrap: wrap;
.box>span
border: 1px solid;
padding: 10px;
flex-grow: 1;
<div class="box">
<span>some text very long here some text very long here </span>
<span>text here</span>
<span>A</span>
<span>B</span>
</div>
This is a 1-D layout where each line may have elements resized differently depending on the free space without being inside a 2-D grid. It will be difficult to achieve the same output using CSS-grid.
Basically flexbox is more suited when it comes to multiline/multirow content following one direction whereas CSS grid is more about a Grid with row and columns. Of course, when it comes to only one line a 2D grid can be considerd as 1D thus flexbox and CSS grid may achieve the same thing.
It's like comparing a table with only one tr
and multiple td
with a set of inline-block
element inside one line BUT when it comes to wrapping and multiple tr
it's clear that table and inline-block
are different.
Worth to note that you can achieve what you want using any techniques in general. In the past, Flexbox wasn't there and developers were able to build layout using float
(Boostrap is the best example). Then flexbox come with more powerful features to make things easier. Same thing for CSS grid and for future features.
Here is an example : https://drafts.csswg.org/css-align-3/
This Draft is talking about a future enhancement of alignment where we can consider jutify-content
, align-items
, etc without even using flexbox or CSS grid but directly on block elements.
If implemented, will this make Flexbox and CSS Grid useless? I don't think so.
.box
display: flex;
flex-wrap: wrap;
.box>span
border: 1px solid;
padding: 10px;
flex-grow: 1;
<div class="box">
<span>some text very long here some text very long here </span>
<span>text here</span>
<span>A</span>
<span>B</span>
</div>
.box
display: flex;
flex-wrap: wrap;
.box>span
border: 1px solid;
padding: 10px;
flex-grow: 1;
<div class="box">
<span>some text very long here some text very long here </span>
<span>text here</span>
<span>A</span>
<span>B</span>
</div>
edited Mar 31 at 14:57
answered Mar 8 at 13:57
Temani AfifTemani Afif
82.2k104794
82.2k104794
add a comment |
add a comment |
I should probably point out that Grid
is MUCH newer than Flexbox
and therefore may actually be intended as a replacement to some extent. Much like Flexbox replaced the typical use case for float
(not the intended use).
I'm going to preface this by saying, I rarely NEED the complexities/capabilities of Grid so I still use Flexbox for most things.
However, in my experience, the flex-wrap
capabilities, especially with variable screen sizes, is one place that I feel Grid isn't a great replacement.
add a comment |
I should probably point out that Grid
is MUCH newer than Flexbox
and therefore may actually be intended as a replacement to some extent. Much like Flexbox replaced the typical use case for float
(not the intended use).
I'm going to preface this by saying, I rarely NEED the complexities/capabilities of Grid so I still use Flexbox for most things.
However, in my experience, the flex-wrap
capabilities, especially with variable screen sizes, is one place that I feel Grid isn't a great replacement.
add a comment |
I should probably point out that Grid
is MUCH newer than Flexbox
and therefore may actually be intended as a replacement to some extent. Much like Flexbox replaced the typical use case for float
(not the intended use).
I'm going to preface this by saying, I rarely NEED the complexities/capabilities of Grid so I still use Flexbox for most things.
However, in my experience, the flex-wrap
capabilities, especially with variable screen sizes, is one place that I feel Grid isn't a great replacement.
I should probably point out that Grid
is MUCH newer than Flexbox
and therefore may actually be intended as a replacement to some extent. Much like Flexbox replaced the typical use case for float
(not the intended use).
I'm going to preface this by saying, I rarely NEED the complexities/capabilities of Grid so I still use Flexbox for most things.
However, in my experience, the flex-wrap
capabilities, especially with variable screen sizes, is one place that I feel Grid isn't a great replacement.
answered Mar 8 at 13:53
Bryce HowitsonBryce Howitson
1,444516
1,444516
add a comment |
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.
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%2f55064488%2fwhat-are-the-areas-covered-by-flexbox-which-are-difficult-or-impossible-to-achie%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