我试图在主(粘性)底部而不是顶部的主网格区域中对齐图像。因此,当视口(viewport)高度扩大时,图像上方必须有更多空间。
我试图使 main 位置相对和 img 位置绝对与 bottom 0 但图像将溢出标题区域。
这是当前的 HTML 和 CSS 代码:
@media screen and (max-width: 576px) and (orientation:portrait) {
html,
body {
height: 100%;
}
body {
margin: 0;
}
body {
display: grid;
grid-gap: 0px;
height: 100%;
grid-template-columns: 1fr;
grid-template-areas: "nav" "main" "footer";
grid-template-rows: 112px 1fr 50px;
}
nav {
grid-area: nav;
}
main {
grid-area: main;
}
footer {
grid-area: footer;
}
nav {
background-image: url('images/header_xs.png');
background-repeat: no-repeat;
}
main {
background-color: #ddf4fb;
}
footer {
background-image: url('images/footer_xs.png');
background-repeat: no-repeat;
}
.logo1_xs {
margin-top: 40px;
margin-left: 60px;
}
.logo2_xs {
margin-top: 10px;
margin-left: 60px;
}
.coastrunner1_xs {
width: 100%;
}
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<nav>
<img class="logo1_xs" src="images/logo1_xs.png" />
<img class="logo2_xs" src="images/logo2_xs.png" />
</nav>
<main>
<img class="coastrunner1_xs" src="images/coastrunner1_xs.png" />
</main>
<footer>
</footer>
</body>
</html>
最佳答案
我用下面的 css 样式完成了它:
main {
display: flex;
flex-direction: column;
}
.flex_space {
flex: 1;
}
并添加了一个空的div:
<main>
<div class="flex_space"></div>
<img class="coastrunner1_xs" src="images/coastrunner1_xs.png" />
</main>
有人有更好的解决方案吗?
关于html - 图像对齐网格区域底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52929269/