【发布时间】:2018-07-25 03:49:32
【问题描述】:
由于 flex,需要将 img 放入动态计算的 li 高度。目前它需要所有高度,并拉高内容。图像应该刚好适合动态计算的 LI 高度,例如50px 并适应它。
不需要硬编码的高度。页面在任何设备中都应为 100%。页眉/页脚 - 弹性:1,主要 - 弹性:3。
body,
ul {
margin: 0;
padding: 0;
}
html,
body,
.root {
height: 100%;
}
.root {
display: flex;
flex-direction: column;
}
main {
flex: 3;
background: lightyellow;
}
ul {
display: flex;
flex-direction: column;
height: 100%;
}
ul li {
flex: 1;
background: aliceblue;
outline: 1px solid #000;
display: flex;
/* align-items: center; */
justify-content: space-between;
}
img {
/* object-fit: contain; */
}
header,
footer {
flex: 1;
}
header {
background: lightgray;
}
footer {
background: lightblue;
}
<div class="root">
<header>
HEAD
</header>
<main>
<ul>
<li>
<img src="http://via.placeholder.com/200x200" />
<span>text</span>
</li>
<li>
<img src="http://via.placeholder.com/200x200" />
<span>text</span>
</li>
<li>
<img src="http://via.placeholder.com/200x200" />
<span>text</span>
</li>
</ul>
</main>
<footer>
FOOTER
</footer>
</div>
【问题讨论】: