css - 带有bootstrap4的Angular 7粘性页脚
问题描述
我正在学习 angular7,我会创建一个粘性页脚。我已经尝试了很多解决方案。
我试过 :
- https://getbootstrap.com/docs/4.3/examples/sticky-footer-navbar/
- stackoverflow中的一些解决方案
- 通过谷歌搜索找到的一些解决方案(像这样)
没有人为我工作。我不明白为什么,我需要帮助。
删除所有我尝试过的代码后,我有这个代码:
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { MenuComponent } from './menu/menu.component';
import { FooterComponent } from './footer/footer.component';
@NgModule({
declarations: [
AppComponent,
MenuComponent,
FooterComponent,
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
index.html(只是正文)
<!doctype html>
<html lang="en">
<head>
...
</head>
<body class="d-flex flex-column h-100">
<app-root></app-root>
</body>
</html>
app.component.html
<app-menu></app-menu>
<main class="container">
<router-outlet></router-outlet>
</main>
<div class="footer mt-auto py-3">
<app-footer></app-footer>
</div>
页脚.component.html
<footer>
© 2019 - Zackna
</footer>
编辑:我用我已经尝试过但删除的@avcajaraville 答案更新了我的代码^-^。还有 我的结果,你可以看到我的页脚没有粘在页面底部。
是否存在引导本机解决方案?我的页脚没有确定的高度。我需要做什么来实现我的目标?
解决方案
根据您的代码示例,您没有添加所需的类。
您可以通过模仿与您提供的示例相同的结构来解决此问题:
索引.html
<!doctype html>
<html lang="h-100">
<head>
...
</head>
<body class="d-flex flex-column h-100">
<app-root></app-root>
</body>
</html>
app.component.html
<app-menu></app-menu>
<main class="container">
<h1>title</h1>
<router-outlet></router-outlet>
</main>
<div class="footer mt-auto py-3">
<app-footer></app-footer>
</div>
我认为这会给你预期的行为。
通常,在使用 CSS 框架时,您需要使用 html 中指定的类。否则,无法应用 CSS。
编辑
我在 index.html 文件的 html 标记上添加了所需的类并重构 app.component.html
推荐阅读
- sql - 多个 UNION 可能更好的 SQL 查询 - 获取不同“键”名称的最新 5 条记录
- spring-cloud-stream - Spring Cloud Stream 和 Spring RetryTemplate 处理嵌套异常
- javascript - 无法使用 discord.js 获得角色
- git - 如何删除 .git 的大包文件?
- java - 如何查找重复的数组列表对象并将少数字段与唯一键合并
- java - MapStruct 映射不相关的相似类
- java - 查找字符串中打开的闭合 html 标记的数量
- c++ - 尝试在 C++ 中实现固定大小的队列时出现分段错误
- drag-and-drop - PyQt5 使用来自另一个文件的 Drop_groupBox()
- r - 找出组中的所有列在 R 中是否一致