【发布时间】:2018-03-12 03:44:23
【问题描述】:
我想知道为什么我在这个带有 display flex 的 div 容器中放置的任何图像都会自动拉伸?如果我要为它设置一个宽度,我不能用justify-content 将它居中。
#container {
display: flex;
justify-content: center;
}
#container div {
padding: 25px;
background: blue;
color: white;
width: 500px;
display: flex;
flex-direction: column;
}
#container div h1 {
display: flex;
justify-content: center;
}
#container input,
#container button {
width: 75%;
}
#container img {
display: flex;
justify-content: center;
}
<div id="container">
<div>
<h1>a</h1>
<img src="https://placehold.it/350x150">
<input type="text" name="a">
<input type="text" name="b">
<button>a</button>
</div>
</div>
https://jsfiddle.net/nqt8bw4z/ 自动拉伸 https://jsfiddle.net/nqt8bw4z/2/ 固定宽度但不居中
【问题讨论】: