Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flex-basis: Webkit / Blink ignore intrinsic aspect ratio

Tags:

css

flexbox

Given a flex container

figure {
  display: flex;
  align-items: flex-start;
}

and a 300x300 image with its flex-basis set at half its intrinsic width:

figure img {
  flex: 0 0 150px;
}

Chrome 41 and Safari 7 ignore the aspect ratio and display it as 150px x 300px:

enter image description here

Firefox 35 on the other hand keeps the intrinsic aspect ratio intact:

enter image description here

figure {
  display: -webkit-box;
  display: -moz-box;
  display: box;
  display: -webkit-flex;
  display: -moz-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: start;
  -moz-box-align: start;
  box-align: start;
  -webkit-align-items: flex-start;
  -moz-align-items: flex-start;
  -ms-align-items: flex-start;
  -o-align-items: flex-start;
  align-items: flex-start;
  -ms-flex-align: start;
  
  width: 100%;
  border: 1px solid black;
}

figure img {
  -webkit-box-flex: 0;
  -moz-box-flex: 0;
  box-flex: 0;
  -webkit-flex: 0 0 150px;
  -moz-flex: 0 0 150px;
  -ms-flex: 0 0 150px;
  flex: 0 0 150px;
}

figure figcaption {
  -webkit-box-flex: 1;
  -moz-box-flex: 1;
  box-flex: 1;
  -webkit-flex: 1 1 auto;
  -moz-flex: 1 1 auto;
  -ms-flex: 1 1 auto;
  flex: 1 1 auto;
}
<figure>
  <img src="//placekitten.com/g/300/300" />
  <figcaption>
    I'm the caption
  </figcaption>
</figure>

Who is correct? I believe the relevant section of the spec is Cross-size determination, but I'm having a hard time interpreting it.

like image 352
janfoeh Avatar asked Feb 17 '15 14:02

janfoeh


People also ask

What do the Flex-grow and flex-shrink properties mean in the demo?

In this example the flex-grow and flex-shrink properties are both set to 1 on all three items, indicating that the flex item can grow and shrink from the initial flex-basis. The demo then changes the flex-basis on the first item.

Does flex-basis work with non-flexible elements?

Note: If the element is not a flexible item, the flex-basis property has no effect. yes. Read about animatable Try it The numbers in the table specify the first browser version that fully supports the property.

What is the use of flex basis in CSS?

The flex-basis CSS property sets the initial main size of a flex item. It sets the size of the content box unless otherwise set with box-sizing. Note: in case both flex-basis (other than auto) and width (or height in case of flex-direction: column) are set for an element, flex-basis has priority.

How does flex-basis size work?

It will then grow and shrink from that flex-basis. This means that, for example, when the flex-basis of the first item is 200px, it will start out at 200px but then shrink to fit the space available with the other items being at least min-content sized.


1 Answers

According the editors draft of the current Flexbox spec, neither of these browsers are rendering this correctly.

When I saw this question posted here, I asked about it on the www-style mailing list, and this is the discussion it prompted (via readable-email.org):

The consensus is that a strict interpretation of the current draft would suggest that the image be sized to 300x300 pixels because that's the minimum content size of the flex item and flex items are not supposed to shrink below their minimum content size if their min-size property is auto (the default, and the case in your example).

Daniel Holbert (Flexbox implementor on Firefox) continued this discussion on another thread where he proposed that items with an intrinsic aspect ration should be allowed to shrink to below their minimum content size. He states:

min-content sizes aren't really a useful lower-bound for flex items with aspect ratios. These flex items can shrink (honoring their intrinsic aspect ratio) below their min-content size, without overflowing.

Anyway, as I said, the answer to your question is that neither browser is rendering this correctly (as per the current spec), but it's possible that the spec will change to handle this case and the way Firefox is currently rendering it will be considered correct in the future.

like image 113
Philip Walton Avatar answered Oct 25 '22 11:10

Philip Walton