html - Why doesn't flex item shrink past content size? -


i have 4 flexbox columns , works fine, when add text column , set big font size, making column wider should due flexbox setting.

i tried use word-break: break-word , helped, still, when resize column small width, letters in text broken multiple lines (one letter per line) column not smaller width 1 letter size.

try watch video: http://screencast-o-matic.com/watch/cdetln1tyt (at start, first column smallest, when resized window, widest column.i want respect flex settings always.. flex sizes 1 : 3 : 4 : 4)

i know, setting font size , column padding smaller help... there other solution?

i can not use overflow-x: hidden.

jsfiddle: https://jsfiddle.net/78h8wv4o/3/

.container {    display: flex;    width: 100%  }  .col {    min-height: 200px;    padding: 30px;    word-break: break-word  }  .col1 {    flex: 1;    background: orange;    font-size: 80px  }  .col2 {    flex: 3;    background: yellow  }  .col3 {    flex: 4;    background: skyblue  }  .col4 {    flex: 4;    background: red  }
<div class="container">    <div class="col col1">lorem ipsum dolor</div>    <div class="col col2">lorem ipsum dolor</div>    <div class="col col3">lorem ipsum dolor</div>    <div class="col col4">lorem ipsum dolor</div>  </div>

the implied minimum size of flex items

you're bumping against minimum sizing algorithm of flex items.

this default setting prevents flex item shrinking past size of content (regardless of other flex factors, such flex-shrink or flex-basis).

the defaults are...

  • min-width: auto
  • min-height: auto

...for flex items in row-direction , column-direction, respectively.

you can override these defaults setting flex items to:

  • min-width: 0
  • min-height: 0
  • overflow: hidden (or other value, except visible)

revised demo

.container {    display: flex;  }    .col {    min-height: 200px;    padding: 30px;    word-break: break-word  }    .col1 {    flex: 1;    background: orange;    font-size: 80px;    min-width: 0;   /* new */  }    .col2 {    flex: 3;    background: yellow  }    .col3 {    flex: 4;    background: skyblue  }    .col4 {    flex: 4;    background: red  }
<div class="container">    <div class="col col1">lorem ipsum dolor</div>    <div class="col col2">lorem ipsum dolor</div>    <div class="col col3">lorem ipsum dolor</div>    <div class="col col4">lorem ipsum dolor</div>  </div>

jsfiddle


flexbox specification

4.5. implied minimum size of flex items

to provide more reasonable default minimum size flex items, specification introduces new auto value initial value of min-width , min-height properties defined in css 2.1.

with regard auto value...

on flex item overflow visible in main axis, when specified on flex item’s main-axis min-size property, specifies automatic minimum size. otherwise computes 0.

in other words:

  • the min-width: auto , min-height: auto defaults apply when overflow visible.
  • if overflow value not visible, value of min-size property 0.
  • hence, overflow: hidden can substitute min-width: 0 , min-height: 0.

and...


multiple levels of flex items

when dealing nested flex containers, may necessary identify flex items on different levels , override min-width: auto / min-height: auto each one. here's example:


browser rendering notes

  • since @ least 2017, appears chrome either (1) reverting min-width: 0 / min-height: 0 defaults, or (2) automatically applying 0 defaults in situations based on mystery algorithm. (this call intervention.) result, many people seeing layout (especially desired scrollbars) work expected in chrome, not in firefox / edge.

  • as noted in spec, auto value min-width , min-height properties "new". means browsers may still render 0 value default, because implemented flex layout before value updated , because 0 initial value min-width , min-height in css 2.1. one such browser ie11. other browsers have updated newer auto value defined in flexbox spec.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -