为什么flexbox拉伸我的形象? [英] Why does flexbox stretch my image?
本文介绍了为什么flexbox拉伸我的形象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< div>
< img src =https://loremflickr.com/400/300>
< h4> Appify< / h4>
< p>一些文字< / p>
< / div>
和这个样式表
div {
display:flex;
flex-wrap:wrap;
img {
width:50%
}
我加了这个codepen 来说明我的意思。
是什么引起的?
解决方案 $ c>默认值是
Set
< pre $
stretch
。 Set
align-self
to center
。 < pre $
align-self:center
b $ b align-self
Flexbox has this behaviour where it stretches images to their natural height. In other (more specific) words, if I have a flexbox container with a child image, and I resize the width of that image, the height doesn't resize at all and the image gets stretched.
<div>
<img src="https://loremflickr.com/400/300" >
<h4>Appify</h4>
<p> some text </p>
</div>
And this stylesheet
div {
display: flex;
flex-wrap: wrap;
}
img{
width: 50%
}
I added This codepen to demonstrate what I mean. What causes this?
解决方案
It is stretching because align-self
default value is stretch
.
Set align-self
to center
.
align-self: center
See doc here: align-self
这篇关于为什么flexbox拉伸我的形象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文