html - 将内容垂直调整到视口
问题描述
我正在创建一个页面来显示照片的放大视图。我希望页面在顶部显示页眉,在底部显示页脚,并且照片的图像填充页眉和页脚之间的所有空间。照片有不同的尺寸,可能有横向或纵向。我没有困难调整视口的宽度。如果页面只包含图像而没有其他内容,我这样做没有问题。尽管进行了搜索、阅读和反复试验,但我无法辨别如何垂直调整内容的大小以满足该准则。例如:
<header>
<h1>Some header stuff</h1>
<p>Such as a navigation bar at the top of the viewport.</p>
</header>
<main>
<h1>Image</h1>
<p>An image that should fill up the space in between</p>
xxxxxxxxxxxxx<br />
xxxxxxxxxxxxx<br />
xxxxxxxxxxxxx<br />
xxxxxxxxxxxxx<br />
xxxxxxxxxxxxx<br />
</main>
<footer>
<h1>Some footer stuff</h1>
<p>Such as a logo, link to privacy page etc.</p>
</footer>
也许这是不可能的。有任何想法吗?
解决方案
header{
height:10vh;
}
footer{
height:10vh;
}
main{
height:65vh;
background:url("https://www.bing.com/th?id=ABT63B35E950543A69BB040AEFA5BFCA186A43A5798E5E9B96844F4CE0ED7176910&w=608&h=200&c=2&rs=1&pid=SANGAM") no-repeat center center fixed;
background-size:cover;
}
<header>
<h1>Some header stuff</h1>
<p>Such as a navigation bar at the top of the viewport.</p>
</header>
<main>
</main>
<footer>
<h1>Some footer stuff</h1>
<p>Such as a logo, link to privacy page etc.</p>
</footer>
推荐阅读
- python - django中的权限与调度方法
- php - Symfony 4 路由不匹配 - redirectToRoute 指向当前页面
- vba - 查找与 MS Word 表格单元格中包含的注释相关的列
- external-tables - Azure Synapse - 字符串分隔符
- r - 脱节时调整 GenomicRanges 对象的元数据
- arrays - Google表格中的数组减法
- javascript - 我不知道为什么 HttpMessageNotReadableException
- flutter - Flutter SliverAppBar,折叠背景填充前导空间
- python - Openrefine,从一个区间获取所有数字
- python-3.x - 将多个列表中的多行写入 CSV