我有一个基本布局,其中我的 CSS 网格位于 flex 布局中,以便网格占据除了页脚之外的所有可用空间。
标头位于position: sticky;.
网格中的项目没有占据网格中可用的所有高度。
在我使用的 CSS 网格布局align-content: space-between;中,这两个项目都位于网格的顶部和底部,中间有一些空白空间。
这在 Chrome 和 FF 上看起来不错,但在 Safari(Mac 和 iOS)上,第二个网格项放在网格之外(按我的粘性标题的高度)。
body {
margin: 0;
padding: 0;
font-family: sans-serif;
text-align: center;
}
.flex {
min-height: 100vh;
width: 100%;
display: flex;
flex-direction: column;
}
header {
position: sticky;
position: -webkit-sticky;
top: 0;
z-index: 999999;
padding: 3em;
background-color: tomato;
}
footer {
padding: 1em;
background-color: tomato;
}
.grid {
width: 100%;
-webkit-flex: 1;
flex: 1;
display: grid;
grid-template-columns: 100%;
grid-template-rows: auto auto;
-webkit-align-content: space-between;
align-content: space-between;
background-color: khaki;
}
.item {
box-sizing: border-box;
padding: 0.6em;
}
.pink {
background-color: pink;
}
.orange {
background-color: orange;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div class="flex">
<header>Header</header>
<div class="grid">
<div class="item pink">Item 1</div>
<div class="item orange">Item 2</div>
</div>
<footer>Footer</footer>
</div>
</body>
</html>