Developing a fixed footer in Angular 7 using the Bootstrap4 framework

I am currently learning angular7 and I have been struggling to create a sticky footer. Despite trying multiple solutions, none seem to work for me.

Here are some of the solutions I have attempted:

Unfortunately, none of these options have worked for me and I am unsure why. I am in need of assistance to resolve this issue.

Below is the code I have after removing all the unsuccessful attempts:

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 (just the body)

<!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>

footer.component.html

<footer>
  &copy; 2019 - Zackna
</footer>

Edit: I updated my codes with @avcajaraville answer that I had previously tried but removed. Here is my result, demonstrating that my footer is still not sticking to the bottom of the page.

I am wondering if there is a native bootstrap solution available? Since my footer does not have a fixed height, what steps do I need to take to achieve my desired outcome?

Answer №1

Big thanks to @avcajaraville for providing the answer. Regrettably, I was unable to grasp the concept in the h-100 class during my attempt and couldn't see any progress.

Fortunately, I was able to discover a solution on my own.

I implemented this CSS code into my app-root component:

app-root {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

Additionally, I applied flex-grow: 1; to my container class.

Answer №2

It seems like you forgot to include the necessary classes in your code samples.

To resolve this issue, try replicating the structure found in the provided example:

index.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>

By following this structure, you should see the desired results.

Remember, it is important to use the specified classes in your HTML when working with a CSS framework to ensure proper styling.

EDIT

I have updated the html tag in index.html file and refactored app.component.html to include the necessary classes.

Answer №3

If you're looking to avoid custom CSS and stick to using Bootstrap utility classes with Angular, here's a simple solution:

In your index.html file, include the following code:


<html class="h-100">
<head>....omitted</html>
<body class="h-100">
    <app-root class="d-flex flex-column h-100"></app-root>
</body>
</html>

Just remember, if you're trying to implement a sticky footer example from Bootstrap4's website in Angular, make sure to apply the utility classes directly to the app-root component rather than the body element. Also, ensure that both the html and body elements have the h-100 class for proper height styling.

Answer №4

I have found the perfect solution to always calculate the total height and set the min-height for the content div, which is 202px in my case. This adjustment ensures that the footer is pushed to the bottom.

.main-content {
    min-height: calc(100vh - 202px);
}

<main>
    <div class="main-content"></div>
    <app-footer class="footer"></app-footer>
</main>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The CSS hamburger menu halves in size when being closed

I have successfully created a CSS/JS hamburger menu with a transforming icon upon clicking. However, I encountered a bug where, upon clicking the 'close' button on the hamburger, the navigation menu cuts behind the header, resulting in a messy ap ...

Guide to creating a clickable inline svg in HTML/CSS for use with onclick event in JavaScript

I have a unique inline svg code snippet in my html: <svg id="nav-search-icon" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32.2 32.2"><path d="M19 0C11.8 0 6 5.8 6 13 ...

Utilize flexbox to keep a paragraph element centered even when the text wraps, without directly centering the

Before this gets down-voted into oblivion, let me mention that I have thoroughly searched through numerous similar questions on SO. However, none of them provided a solution to my specific issue. I am using flexbox to align <p> tags both horizontall ...

Automatically changing the page's background color through animation upon loading

Similar Question: jQuery animate backgroundColor Can I make the background-color of a specific element change gradually when the page loads? I have a webpage with content like this: <ul> <li> Some stuff</li> <li> Some ...

What is the best way to create a mirrored effect for either a card or text using CSS

Can anyone assist me with this CSS issue? When I hover over to view the movie details, the entire word flips along with it. Is there a way to make only the word flip initially, and then have it return to normal when hovered? The HTML code is included belo ...

Distinguishing appearances among various web browsers

How come the menus look different in Firefox compared to Chrome, Safari, and IE? I've tried adjusting the CSS but can't seem to get it just right. Any suggestions on how to fix this? In Firefox, there's an overlapping part at the bottom of ...

Stylish Navigation Menu Logo/Site Name

Currently in the process of upgrading my website and I have my website name included as part of my menu, as opposed to a logo. This has been an easy solution that has worked well for me. For mobile screens, the template I purchased includes a slicknav men ...

Shifting Elements - Navigation triggers subtle movements in CSS styles as you move across pages

I've noticed a strange issue on my website where certain elements seem to be shifting slightly when navigating between different pages. Here's a quick video clip demonstrating the problem. It appears that these elements are not staying static as ...

Enhancing Connectivity between Angular and Electron

I'm currently in the process of integrating my Angular application with Electron and I am looking to bind and send messages from Electron to Angular. Below is a snippet of my code: App.module.ts: import { NgxElectronModule } from 'ngx-electron& ...

Issue with displaying Bootstrap 4 Navbar toggle on iPad devices

I am encountering an issue with the Navbar header in Bootstrap 4 beta on my iPad. While it works perfectly on small devices, it is not displaying correctly on my iPad. Can someone please assist me in fixing this issue? If you need to see the problem in act ...

I require fixed headers that no longer stick once reaching a specific point

I have a setup where the names and occupations of participants are displayed next to their artworks, and I've made it sticky so that as we scroll through the images, the names stay on the left. Now, I want the names to scroll out once the images for e ...

My website has a navbar button that is not directing to the intended section of the screen

I have created this HTML code for my Navbar buttons: <button class="navbar-toggle" data-toggle = "collapse" data-target=".navHeaderCollapse"> <span class="icon-bar"></span> <span class="icon-bar">< ...

The process of eliminating body padding in Nuxt.js

I'm considering building a website using Nuxt.js because I've heard it's both cool and user-friendly. While I do have some knowledge of vue.js, I'm stuck on a particular issue: How can I remove the padding from the body? I understand ...

Placing an Image in the Right Corner Using jQuery Mobile

I am currently developing a mobile app and I need to align three images one below the other at the right corner next to some text. Any suggestions would be greatly appreciated. Thank you in advance. Below is my code snippet: <div> <ul data-r ...

utilizing the value within the useState function, however, when attempting to utilize it within this.state, the tab switching feature fails

I am struggling to implement tab functionality in a class component. Even though I'm using this.state instead of useState, the tab switching is not working correctly. I have read the following articles but still can't figure it out: http ...

The CSS link will only appear when hovering over the image

I'm having trouble getting the f1 link to appear on an image only when hovering over the image. I tried some code but it's not working, the link is not appearing. Can someone help me understand what the problem is and provide a solution? <div ...

Is it advisable to incorporate different React UI libraries within one project?

Is it acceptable to mix different UI libraries when coding? I currently use react-bootstrap in my project, but I am thinking about incorporating React Suite for future components. What are the guidelines for using multiple UI libraries in a project? ...

Tips for aligning an image within a CSS-created bar graph

Would it be possible to position an image inside each bar of a bar graph without changing the bar's size? I've figured out how to do this with text, but not with an image. Alternatively, would it be better to place the image to the left of each b ...

Tips to store Google fonts in the assets directory

I've included this link in my styles.scss @import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&display=swap'); While it works locally, the API fails on production or is blocked. How can I host it within my p ...

Background images at 100% width are not causing horizontal scrolling issues

I've come across an interesting problem. I created a quick screen recording to illustrate: Essentially, when you specify a min-width and the viewport width falls below that limit, a horizontal scroll bar appears. This behavior is expected, but when s ...