Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of flex-basis: content

Tags:

html

css

flexbox

I noticed in the flexbox specification that flex-basis can be set to content.

I'm trying to use that in the html. But it's not working in chrome.

Can someone show me an example for flex-basis: content?

Thank you.

like image 968
Emma Avatar asked Mar 23 '16 16:03

Emma


People also ask

What is a flex basis?

The flex-basis property is a sub-property of the Flexible Box Layout module. It specifies the initial size of the flex item, before any available space is distributed according to the flex factors. When omitted from the flex shorthand, its specified value is the length zero.

What is the difference between Flex and Flex basis?

flex: 0 1 200px; Here flex-basis is acting like a maximum width. An element that has a flex shrink value of 0, a flex grow value of 0, but has a flex basis pixel value, will only ever be that pixel value size. It won't shrink and it won't grow. This would be the same as setting a pixel value to the width property.

What is Flex content in CSS?

A flex container expands items to fill available free space or shrinks them to prevent overflow. Most importantly, the flexbox layout is direction-agnostic as opposed to the regular layouts (block which is vertically-based and inline which is horizontally-based).


1 Answers

Note that the content value is not yet supported by most major browsers.

Here's a screenshot from MDN:

enter image description here

For an explanation about what content does, MDN is also helpful:

content

Indicates automatic sizing, based on the flex item’s content.

Note: Note that this value was not present in the initial release of Flexible Box Layout, and thus some older implementations will not support it. The equivalent effect can be had by using auto together with a main size (width or height) of auto.

Note: Brief history

  • Originally, flex-basis: auto meant "look at my width or height property".
  • Then, flex-basis: auto was changed to mean automatic-sizing, and "main-size" was introduced as the "look at my width or height property" keyword.
  • Then, that change was reverted, so auto once again means "look at my width or height property"; and a new content keyword is being introduced to trigger automatic sizing.

source: https://developer.mozilla.org/en-US/docs/Web/CSS/flex-basis#Values

like image 133
Michael Benjamin Avatar answered Oct 04 '22 06:10

Michael Benjamin