material icon indicating copy to clipboard operation
material copied to clipboard

Nested layouts and flex

Open mnn opened this issue 11 years ago • 13 comments

Flex seems to be broken on Chrome when used in a nested layout. Firefox renders it as expected.

I'm new to Angular Material so it might be my fault somehow. If this is expected bahaviour what is recommended solution? I have tried a lot of different combinations without any luck, I would welcome any suggestions on solving this.

Pictures

Firefox

Firefox

Chrome

Chrome In an inner layout only attribute "flex" without value works.

Code

http://codepen.io/monnef/pen/xGPXvB

Relevant snippet:

  <body layout="row" ng-controller="AppCtrl">
    <div flex="30" layout="column" class=a>
      flex="30"
      <md-card flex="40">flex="40"</md-card>
      <md-card flex>flex</md-card>
    </div>
    <div flex layout="column" class=a>
      flex
      <md-card flex="70">flex="70"</md-card>
      <md-card flex="10">flex="10"</md-card>
    </div>
  </body>

mnn avatar Jun 24 '15 10:06 mnn

@mnn - See Nested Flex Containers demo where the card containers (using class "a" or "boxWithHeight") have an explicit height style attribute.

Per feedback from @gkalpak:

Relevant spec sections:

  1. flex-basis
  2. definite/indefinite sizes

Summary:

  • flex="XYZ" setsflex: 0 0 XYZ%=>flex-basis: XYZ%`.
  • Because it is a percentage value and it is resolved against the flex container's indefinite block size, it becomes equivalent to flex-basis: auto.
  • Since there is no height value (so it is by default auto), it falls back to flex-basis: content.
  • The flex-basis is determined by the element's content (not our specified XYZ :disappointed:).

I am not 100% sure I am interpreting the spec correctly, but it kind of makes sense :)

Setting a different height value on the flex-container (e.g. height: 100%), makes everything work as expected. (Updated demo)

ThomasBurleson avatar Jun 30 '15 16:06 ThomasBurleson

Now say I want to nest another one in there, it doesn't work. Is there a way to keep nesting them properly to get the correct vertical split?

http://codepen.io/anon/pen/WvWRqp

You don't seem to be able to get a proper height % wise inside a flex child.

amritk avatar Aug 13 '15 01:08 amritk

+1 Looking for a solution when using multiple layers of nesting as well.

jdwilliams15 avatar Aug 21 '15 15:08 jdwilliams15

@ThomasBurleson your solution is not working

pexak avatar Sep 23 '15 11:09 pexak

@Pexak - Your comment is not very helpful.

  • Do you have a snapshot ?
  • Can you provide more details ?
  • Which browser and version are you using ?

ThomasBurleson avatar Sep 23 '15 11:09 ThomasBurleson

@ThomasBurleson Sure, sorry, I'm using Chrome 45 and firefox 31 It seems your codepen example - http://codepen.io/anon/pen/PPGNEm is not working, sections area do not expand to flex value, it only adjust to text size

pexak avatar Sep 23 '15 11:09 pexak

To use Angular Material Layouts, you *MUST *create an ng-app with a 'ngMaterial' dependency. Here is an updated CodePen that works: http://codepen.io/ThomasBurleson/pen/wKzOvm

  • We do not support FireFox 31
  • Chrome works (with some fixes)

Our browser support is N-1 where N === browser's current release version.

ThomasBurleson avatar Sep 25 '15 02:09 ThomasBurleson

@ThomasBurleson I'm having a similar issue with nesting, and it's a regression since 0.10.0 (the last version I used). Looking at the CodePen you linked, I'm seeing a similar issue -- the nested items' flex heights aren't being respected.

jmuharsky avatar Oct 13 '15 19:10 jmuharsky

Fixed and working in master. See CodePen http://codepen.io/ThomasBurleson/pen/wKzOvm

screen shot 2015-10-15 at 8 30 24 pm

ThomasBurleson avatar Oct 16 '15 01:10 ThomasBurleson

just to further illustrate, OP's codepen looks even worse on Safari 9.0.1, with no height at all

screen shot 2015-10-28 at 15 29 30

That explains why my page crawled into a ball..

it seems like adding height to layout="column" elements solves it http://codepen.io/anon/pen/WQJKvj

ThadeuLuz avatar Oct 28 '15 19:10 ThadeuLuz

With 1.0.0-rc4 I'm seeing strange behavior with Chrome. I don't really understand the root issue to provide much constructive feedback here, but I posted a question on stackoverflow trying to get some help with why the vertical heights of flex'd elements don't work intuitively in Chrome:

http://stackoverflow.com/questions/33785146/building-simplest-gmail-layout-with-angular-material-chrome-issue

Here's the codepen I created to illustrate the issue: http://codepen.io/sstorie/pen/ZbPybm

sstorie avatar Nov 18 '15 17:11 sstorie

@ThomasBurleson Your CodePen doesn't seem to work with another level of nested vertical flexes:

http://codepen.io/anon/pen/VeeOER

Is this considered a bug?

jbcpollak avatar Dec 17 '15 01:12 jbcpollak

Also when we try to change the flex value of row from 30 to 40 or any other value, then chrome fails to apply.

kapil-kharade avatar Feb 07 '16 13:02 kapil-kharade