僅當有足夠空間時纔會考慮margin-bottom
。否則,Firefox的行爲就好像根本沒有margin-bottom
。爲什麼Firefox會忽略flex-item的底部邊距?
Chrome的全部:
鉻收縮:
火狐收縮:
是否正確flexbox的行爲?如何解決它?
.container {
position: fixed;
display: flex;
flex-direction: column;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow: auto;
}
.grow {
flex-grow: 1;
flex-shrink: 0;
background: #8f8;
}
.content {
width: 500px;
margin: 20px auto;
border: 1px solid currentColor;
background: #f88;
}
<body>
<div class="container">
<div class="grow"></div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatibus, facilis omnis inventore, illum eos quis fuga quos id, labore consectetur quas. Unde sed nemo nobis recusandae saepe ex nulla accusantium?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias asperiores a enim magnam voluptatem. Ab sint possimus quis odit vero explicabo unde quod rem, quasi voluptatibus cupiditate voluptatem veritatis repudiandae.</p>
</div>
<div class="grow"></div>
</div>
</body>
考慮增加一個'柔性basis'爲'.grow'。 https://codepen.io/anon/pen/LLVpZN?editors=1100 –
@Michael_B使用'flex-basis'你將強制擁有至少1px高的'.grow'元素。當屏幕太小時,我不想要它們。 – vbarbarosh