2

I'm trying to create a sticky footer with angular material and flexbox. It looks like I have succeeded using flex-grow: 1 !important; on my main content element, but it only works as long as I use that code on the element with a style="" property. Other options to apply the same rules do not work:

  • Applying the CSS in an external file (even with !important)
  • Applying the CSS in a style element (even with !important)
  • Using flex properties in the element like flex="none" flex-grow"1"

It looks like either angularJS or Angular Material overrides my settings except for the style="" property. How can I change this behavior?

I'm suspecting the Angular Material javascript to set my flex-grow property to 0, while I want it to be 1, because the property is always at 0 on page load, no matter what I try with CSS and flex properties. Am I right? Is there a good reason for this?

EDIT: I have found multiple examples on how to create a sticky footer, but they all don't work for me. The single solution I have found is the one with a style property mentioned above and I would like a simpler solution.

For example, I cant get this one to work because it would set the flex-grow value to 0.

https://codepen.io/rscafi/pen/bNXRxY/

1 Answer 1

1

I'm not sure why you would use flex: none and flex-grow: 1 in the same declaration.

flex: none breaks down to this:

  • flex-grow: 0
  • flex-shrink: 0
  • flex-basis: auto

Then you're overriding the flex-grow above with flex-grow: 1

You should just consolidate both rules. That would look like this: flex: 1 0 auto

Sign up to request clarification or add additional context in comments.

4 Comments

I realized that as soon as I posted the question. I see now that my solution works because it forces flex-grow: 1;. It still only works in a style property. EDIT: Nevermind. Your rule in combination with !important seems to work.
Thanks for explaining that flex-grow is part of flex, I didn't know that yet. Your solution works in separate CSS without the !important tag, and that's all I wanted. It seems flex has some funky interactions when you override rules in the same element, but that's not unacceptable.
The flex property is shorthand for: flex-grow, flex-shrink, flex-basis.
My main element looked like this: <main class="md-padding" layout="row" style="flex:none; flex-grow:1;">. That worked, and the same ruleset of flex defined in any other location wouldn't work. But your answer is basically the correct way of defining what I was trying to do, and your rule works in every way I need it to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.