css - Flex box and percentage width hiding image -


consider following html

<menu class="main">     <menuitem><img src="blah" class="foo"></menuitem> </menu> 

these elements styled using flexbox

menu {   display: flex;   margin: 0;   align-items: stretch; }  menuitem {   flex: 1 0 auto;   align-items: center }  .foo {   display: flex;   flex: 0 0 25%;   max-width: 25%;   margin-left: auto; //align far right } 

this works expected except if flex , width percentages, when resize screen, rather staying on right edge of menu bar begins disappear. there way image stay pushed right screen resized?

please note i'm using chrome test, have observed same behavior on safari. i'm using autoprefixer take care of vendor prefixes.

edit

here plunk. http://plnkr.co/edit/bnupwqnbdx9jm2e7zvna?p=preview when resize viewport, playstation logo moves off screen instead of moving fit available space.

just add flex-direction:column menu

and change:

.foo { max-width:25% } 

to

.foo { max-width:100% } 

so image fit naturally.

p.s. - used different image because image encoded. here snippet:

menu {    display: flex;    margin: 0;    align-items: stretch;    background: blue;    flex-direction:column;  }    menuitem {    flex: 1 0 auto;    align-items: center  }    .foo {    display: flex;    flex: 0 0 25%;    max-width: 25%;    margin-left: auto;   }
<menu class="main">      <menuitem><img height="200" src="http://i1303.photobucket.com/albums/ag160/trekmd/rvg%20images/playstationonelogo_zps6b738565.png  " class="foo"></menuitem>    </menu>


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -