将 div 与容器底部对齐
Align div to the bottom of a container
我正在使用 骨架 CSS,我正在尝试让 div
位于页面底部。
我试过在容器中使用 position: absolute; bottom: 0;
有一个相对位置,但是 div
只是对齐到页面的右侧。
.page {
align-items: center;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
min-height: 100vh;
}
#home {
background: red;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<div class="page" id="home">
<div class="container" style="text-align: center;">
<div class="row">
I am a title in the middle of the page.
</div>
<div class="row" style="">
I want to be at the bottom of the page.
<br>
<a href="#">Click here!</a>
</div>
</div>
</div>
请问这样可以吗?
从 CONTAINER 父元素中取出 Bottom 文本元素并将其作为 PAGE 元素的子元素放置,然后 position:absolute 将起作用:
https://jsfiddle.net/akLr6zb0/
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<div class="page" id="home">
<div class="container" style="text-align: center;">
<div class="row">
I am a title in the middle of the page.
</div>
</div>
<div class="bottom" style="">
I want to be at the bottom of the page.
<br>
<a href="#">Click here!</a>
</div>
</div>
.page {
align-items: center;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
min-height: 100vh;
position: relative;
}
#home {
background: red;
}
.bottom {
bottom: 0;
display: block;
position: absolute;
}
position: absolute; bottom: 0;
是对的,但是你还需要确保直接父级 .container
是页面的高度,然后将所有内容居中 display: flex
:
.page {
min-height: 100vh;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
#home {
background: red;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<div class="page" id="home">
<div class="container" style="text-align: center;">
<div class="row">
I am a title in the middle of the page.
</div>
<div class="row" style="position: absolute; bottom: 0;">
I want to be at the bottom of the page.
<br>
<a href="#">Click here!</a>
</div>
</div>
</div>
我不确定这是否是您想要的,但我通过将容器显示为 flex 实现了这一点。
.page {
align-items: center;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: center;
min-height: 100vh;
}
#home {
background: red;
}
.container {
flex-grow: 1;
display: flex;
align-items: center;
justify-content: center;
}
.bottom {
position: absolute;
bottom: 0;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<div class="page" id="home">
<div class="container">
<div class="row">
I am a title in the middle of the page.
</div>
<div class="row bottom" style="">
I want to be at the bottom of the page.
<br>
<a href="#">Click here!</a>
</div>
</div>
</div>
我正在使用 骨架 CSS,我正在尝试让 div
位于页面底部。
我试过在容器中使用 position: absolute; bottom: 0;
有一个相对位置,但是 div
只是对齐到页面的右侧。
.page {
align-items: center;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
min-height: 100vh;
}
#home {
background: red;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<div class="page" id="home">
<div class="container" style="text-align: center;">
<div class="row">
I am a title in the middle of the page.
</div>
<div class="row" style="">
I want to be at the bottom of the page.
<br>
<a href="#">Click here!</a>
</div>
</div>
</div>
请问这样可以吗?
从 CONTAINER 父元素中取出 Bottom 文本元素并将其作为 PAGE 元素的子元素放置,然后 position:absolute 将起作用:
https://jsfiddle.net/akLr6zb0/
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<div class="page" id="home">
<div class="container" style="text-align: center;">
<div class="row">
I am a title in the middle of the page.
</div>
</div>
<div class="bottom" style="">
I want to be at the bottom of the page.
<br>
<a href="#">Click here!</a>
</div>
</div>
.page {
align-items: center;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
min-height: 100vh;
position: relative;
}
#home {
background: red;
}
.bottom {
bottom: 0;
display: block;
position: absolute;
}
position: absolute; bottom: 0;
是对的,但是你还需要确保直接父级 .container
是页面的高度,然后将所有内容居中 display: flex
:
.page {
min-height: 100vh;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
#home {
background: red;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<div class="page" id="home">
<div class="container" style="text-align: center;">
<div class="row">
I am a title in the middle of the page.
</div>
<div class="row" style="position: absolute; bottom: 0;">
I want to be at the bottom of the page.
<br>
<a href="#">Click here!</a>
</div>
</div>
</div>
我不确定这是否是您想要的,但我通过将容器显示为 flex 实现了这一点。
.page {
align-items: center;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: center;
min-height: 100vh;
}
#home {
background: red;
}
.container {
flex-grow: 1;
display: flex;
align-items: center;
justify-content: center;
}
.bottom {
position: absolute;
bottom: 0;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<div class="page" id="home">
<div class="container">
<div class="row">
I am a title in the middle of the page.
</div>
<div class="row bottom" style="">
I want to be at the bottom of the page.
<br>
<a href="#">Click here!</a>
</div>
</div>
</div>