The HTML footer designed with bootstrap is not behaving as expected. It is not staying fixed at the bottom of the page and is not displaying at full width despite my coding efforts

Working on a small Sinatra app with bootstrap for layout, I'm encountering some issues.

The layout is not sticking to the bottom and not displaying at 100% width as intended. Additionally, the footer text is not centering even after applying the text-center class.

Here is the HTML code for the footer:

<div class="container-fluid">
     <footer id="footer">
       <p class="mx-auto">&copy; 2017 <strong>Coding Tips</strong></p>
     </footer>
</div>

Below is the CSS for the footer:

#footer {
  background-color: white;
  color: #111111;
  position: relative;
  z-index: 1
  bottom: 0;
  left: 0;
  width: 100%;
  /*height: 20px;*/
  align-content: center;
}

Any ideas on how to resolve these issues?

Answer №1

Here's a simple method to create a sticky footer with Bootstrap without the need to manually write CSS styles. The Bootstrap navigation bar component includes the .navbar-fixed-bottom class, which allows you to affix a navbar to the bottom of the screen. For instance,

p {
  text-align: center;
  padding: 10px
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<nav class="navbar navbar-default navbar-fixed-bottom">
  <div class="container-fluid">
    <p>&copy; 2017 <strong>Coding Tips</strong></p>
  </div>
</nav>

By using this approach, you can achieve a sticky bottom navigation bar that functions as a footer solely with Bootstrap.

Edit - Crafting a sticky footer that adjusts with page size.

The previous example showcases a fixed footer at the bottom of the viewport, overlaying the page content. If you prefer a footer that sticks to the bottom when content is sparse, we can utilize flexible boxes.

body {
  margin: 0; /* To ensure the footer takes up the full width of the viewport */
}

.container {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.content {
  flex: 1;
}

footer {
  text-align: center;
}
<div class="container">
  <div class="content">
    Your content goes here.
  </div>
  <footer>
    <p>&copy; 2017 <strong>Coding Tips</strong></p>
  </footer>
</div>

The .content class automatically utilizes the available space, moving the footer to the screen's bottom. With the minimum height of .container set to 100vh, it will occupy at least the entire screen height. As more space is required, the footer adjusts further down. Flexbox offers a straightforward and elegant solution for achieving this effect.

Bootstrap navbars: Components - Bootstrap
Solved by Flexbox: Sticky Footer - Solved by Flexbox - Cleaner, hack-free CSS

Answer №2

In order to center align text, you can use the following CSS code:

text-align: center;

The width can be set to 100% as required. To position the footer at the bottom, you can add:

top: 400px;

For a live example, please visit the following link: https://example.com

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

Tips for enabling a flexbox item to extend beyond its container

While attempting to utilize flexbox for creating a navbar with the logo in the center, I encountered an issue where the logo wasn't able to overflow from above and below the navbar. I experimented with squeezing in and positioning the element, but it ...

Using setTime in JavaScript allows for customizing and adjusting the

I'm having trouble getting this code to display the time. I thought it would work, but it's not showing the time. Can someone please help me figure out what's going wrong? function startTime() { var currentTime = new Date(); ...

What steps can be taken to customize this code in order to develop a dictation application?

Currently, I have a code that functions by comparing two strings: str2 (which represents user input) and str1 (our reference string). The purpose is to determine whether any words in str2 are spelled correctly or incorrectly. So far, the code works well. H ...

What is the best way to design a webpage that adapts to different screen heights instead of widths?

I'm in the process of designing a basic webpage for a game that will be embedded using an iframe. The game and text should always adjust to fit the height of your screen, so when the window is small, only the game is displayed. The game will be e ...

Setting a maximum character limit for an HTML textarea

I am currently attempting to limit the maximum number of characters allowed in a textarea. Using: <textarea rows="4" cols="50" maxlength="50"> It is functioning correctly in Firefox, but there is no impact in IE. This is an issue as many website u ...

Center an element on the screen by dynamically adjusting its position according to the media query

As I work on creating a responsive website that can adapt to screens of various devices, I am facing a challenge. Each device has a different number of pixels, making it difficult to centrally position a div dynamically. Currently, I am using margin-left: ...

Issues with implementing Bootstrap 4 navbar on a Rails 5 application

I'm currently in the process of transitioning my static HTML/CSS/JS website to a Rails application. Using Bootstrap 4, I had all the functionality and CSS classes working perfectly on the static site. However, after the migration to the Ruby app, the ...

Notification (jQuery) failing to display user messages

Is there a way to retrieve the post title and display it in a notification? The notification's title is extracted from a form and shown in the notification. When the user clicks the submit button, the system captures the duration and title, displaying ...

Get the value of an HTML element

Is there a way to retrieve the value of an HTML element using PHP or JavaScript, especially when the value is dynamically loaded from another source? I have tried using jQuery with the DOM ready event, but often encounter the issue where the element's ...

having difficulty retrieving the initial selected value of a dropdown using selenium

Situation 1: On the screen, there are two fields named district and territory. Some users have a default value already selected in these fields, with the drop down disabled. Below is the code snippet for reference. <select id="abcd" name="xyz" clas ...

Is it possible to use -webkit-transform with dual background layers?

I've implemented a unique animation for a div that features two semi-transparent backgrounds: /* Custom keyframes for the animated background DIV. */ @-webkit-keyframes wind { 0% { background-position: 0px 0px, 0px 0px; } 100 ...

Which tag is best to use for applying a CSS style to a section of text?

When it comes to styling text, I usually opt for one of the following methods: <span class="header">...</span> <div class="header">...</div> <p class="header">...</p> <label class="header">...</label> Howeve ...

The submit button fails to function properly in the presence of multiple fields

Encountering an issue where the Submit button becomes unresponsive when multiple addresses are generated. To resolve this, I attempted to use JavaScript. @foreach ($userDetails as $addr) <div class="order_container"> <input type="hid ...

Attempting to show an image in an Android app with the help of Worklight framework

I am currently developing an android application utilizing the worklight platform and am relatively new to html and javascript. I am attempting to showcase an image in the top row of a table within the app by implementing the following html code: <tr& ...

Update picture using Vanilla Javascript for mobile display

I am looking to change my logo color to white when viewed on mobile devices. Currently, I have the following code for changing the logo on scroll using vanilla JavaScript. The code toggles between a dark and light logo based on the scroll position. Howev ...

In HTML 5, you can use either #Header or the <header> tag

I'm feeling a bit puzzled about html right now, so I have a question regarding the use of semantic elements: Should I structure my code like this? <html> <head> <title>Some page</title> </head> <body> < ...

Click on the submenu to expand it, then simply select the desired option to navigate

I have created a toggle menu that displays a list of child elements when clicked, and hides them if clicked again. However, when a child element is clicked, I want it to navigate to the corresponding page. I am having trouble getting this functionality to ...

What causes the delay in CSS animations?

Is there a way to trigger an "updating" image to spin while a long JavaScript function is running? I am currently using JQuery to add a class called "spinning", defined in my CSS for the animation. The problem is that when I add the class and then call a l ...

A versatile CSS solution for fixed background images that stretch to fit any screen height across multiple browsers

Similar Question: Stretch and Scale CSS Background I am interested in finding a method to create a background with specific criteria: - remain fixed in place - adjust proportionally based on the window's height - work across all browser types or ...

Altering the character by striking a key

I have a canvas with custom styling. In the center of the canvas is a single letter. Please see the code below for reference. The goal is to change the displayed letter by pressing a key on the keyboard. For instance: Letter A is centered in the canvas: P ...