css flex 图片不拉伸_CSS Flexbox图像不保留宽高比

I'm trying to learn to use Flexbox. I have a page with two images separated by a bar in the middle, stacked top to bottom. I want the bar to stay the same size regardless of the browser and the two images to resize when the browser shrinks (keeping the original image size if there is extra space. I'm enforcing this through max-height on the containing divs). I can get the images to resize height-wise, but the width doesn't change to maintain aspect ratio.

I've read a couple similar questions and tutorials, but I can't seem to apply their solutions to fit my scenario. This solution seems to be the closest to my needs: http://goo.gl/iE6Wbh

Here is what I have so far. I don't know why it's causing the content to scroll on codepen either... http://codepen.io/anon/pen/VLvxgo

#container

{

width: 100%;

height: 100%;

display: flex;

flex-direction: column;

flex-wrap: nowrap;

justify-content: center;

align-items: center;

}

.topbottom

{

flex: 3;

display: flex;

}

.topbottom.top

{

max-height: 93px;

}

.topbottom.bottom

{

max-height: 152px;

}

.topbottom > img

{

width: auto;

height: 100%;

}

#dividerbar

{

background-color: blue;

width: 100%;

height: 50px;

margin: 20px 0;

}

Hello world

Any thoughts?

解决方案

I'm currently working on a similar problem and it seems to be a bit tricky. I found a solution which works in safari, but won't work in chrome and firefox. They ignore the

max-height: 100%;

property. Check this out and resize browser.

Although i'm not 100% sure what you are trying to achieve (your codepen doesn't change anyhow when resizing the browser window), i've build this one.

Let me know if it's the right direction

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值