html - 如何在 HTML 和 CSS 中将元素固定到容器的底部?
问题描述
我正在尝试制作一个简单的投资组合网站,每当我向下或向上导航页面时,我都希望屏幕底部有两个标签。例如,如果我在页面顶部,它会用三个链接显示我的名字,“关于我”、“我的工作”和“联系方式”。如果我点击“关于我”,它会将我向下导航到我拥有该部分的位置。然后这就是我需要帮助的地方,我想要底部的“我的工作”和“联系方式”以便于导航。几个小时以来,我一直试图弄清楚这一点,这就是为什么我现在在这里提出问题。我是网络编程新手,请原谅。这是我的一些相关代码。
#container {
padding-top: 100vh;
width: 100%;
height: 100vh;
color: white;
}
#container div {
position: relative;
width: 100%;
height: 100%;
}
/* Styling for each indivual link (About Me, My Work, Contact) */
#container div#AboutMe {
background: white;
color: black;
font-family: Helvetica;
font-weight: lighter;
text-align: center;
font-size: 21px;
}
#AboutMe p {
padding-right: 60%;
padding-left: 10%;
padding-top: 5%;
}
.animatedButtonBody span {
cursor: pointer;
display: inline-block;
position: relative;
-webkit-transition: 0.5s;
-o-transition: 0.5s;
transition: 0.5s;
}
.animatedButtonBody span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
-webkit-transition: 0.5s;
-o-transition: 0.5s;
transition: 0.5s;
}
.animatedButtonBody:hover span {
padding-right: 25px;
}
.animatedButtonBody:hover span:after {
opacity: 1;
right: 0;
}
<div id="container">
<div id="AboutMe">
<h1>About Me</h1>
<p>
This is where some text will go.
</p>
<a href="#MyWork" class="animatedButtonBody"><span>My Work</span></a>
<a href="#Contact" class="animatedButtonBody"><span>Contact</span></a>
</div>
</div>
解决方案
您可以尝试位置:固定。你也应该整理你的 html 元素(在 div 中包装东西等)
例子:
.nav {
height: 60px;
background-color: grey;
}
.content{
height: 500px;
background-color: lightgreen;
}
.footer{
height: 60px;
width: 100%;
background-color: black;
position: fixed;
bottom: 0px;
}
<div class = "container">
<div class = "nav">
</div>
<div class="content">
</div>
<div class = "footer">
</div>
</div>
希望能帮助到你
推荐阅读
- c - 使用make的时候提示“系统找不到指定的路径”,但是路径是正确的,这是为什么呢?
- c# - 使用 C# 位图更有效地将图像保存到磁盘
- python - 针对数据帧 2 中的多个段实例检查数据帧 1 中的段长度
- c - 一个程序使用的多个共享库可以使用不同的静态链接库吗?
- rust - 借用 self 是可变的和 self 的成员是不可能的?
- angular - 如何拦截柏树中的GetById?
- flutter - 无法使用Provider时如何将数据注入类?- 颤振
- python - python:在for循环中创建嵌套列表
- jquery - JQuery 缩放代码不适用于光滑的滑块
- html - 在 CSS 或 SVG 中带边框和剪裁右上角的 Div