Front-end education for the real world. Since 2018.





Prevent squishy elements with flex none

Andy Bell

Topic: CSS

You can prevent elements like <svg> icons getting squished in a flexbox context by setting flex to none.

Code language
css

.no-squish {
  flex: none;
}

This is really handy if you have a supporting icon because the default behaviour of a flex parent is to not wrap, which means elements will be forced to shrink as space runs out.

Setting flex to none gives you an inflexible item that can’t grow or shrink, based on the flex rules set on the parent, so it’s ideal for extrinsically sized elements, like icons.

See the Pen Flex none demo by piccalilli (@piccalilli) on CodePen.

Enjoyed this article? You can support us by leaving a tip via Open Collective


Newsletter