Tips for positioning a 404 message at the center of a webpage

Struggling with centering a 404 error message on your Bootstrap 5 page without messing up the footer layout? When the viewport is small, the 404 message may end up getting covered by the footer. Feel free to check out the code snippet in full view to see how the current 404 page appears.

/* body {
    margin: 0;
    padding: 0;
    font-family: "Montserrat", sans-serrif;
    min-height: 100vh;
} */

#error-message {
    text-align: center;
  position: absolute;
  top:50%;
  transform: translateY(-50%);
}

#footer {
    position: absolute;
  bottom: 0;
  width: 100%;
}



 footer p {
    padding-top: 8px !important;
  }
  
  @media screen and (min-width: 768px) and (max-width: 991px) {
    footer h4 {
      min-height: 56px;
    }
  } 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <title>404 |  </title>
    <link rel="stylesheet" href="./css/404.css>
    <link rel="stylesheet" href="/_bridgetown/static/css/main.c7d4dd3f1984a290e9be.css" />
<link href="https://cdn.jsdelivr.net/npm/email-protection(cbbbd2c803c2d6dbdbc1cda158756b65cbcddb2)" rel="stylesheet">

<!-- More links... -->

<script src="https://cdn.jsdelivr.net/npm/email-protection(91326f6f74747476757070357461746281386578)/dist/js/bootstrap.bundle.min.js></script>


<!-- Page content starts here -->
    <div class="container"id="error-message">
        <h2>Oops! Page not Found</h2>
            <h1>404</h1>
            <p>Sorry, we can't find the page you are looking for.</p>
            <p>If you clicked a link on our site and were deirected to this page please contact us so we can fix the problem.</p>
            <a href="./index.html>Go back home</a>
    </div>

    <!-- Footer section -->
    <footer class="bg-dark text-white" id="footer">
          <!-- Footer content goes here -->
    </footer>
      <!-- End of footer section -->
</body>
</html>

Answer №1

#error-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 10%;
}

#footer {
  position: absolute;
  bottom: 0;
  width: 100%;
}

footer p {
  padding-top: 8px !important;
}

@media screen and (min-width: 768px) and (max-width: 991px) {
  footer h4 {
    min-height: 56px;
  }
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>404 | </title>
  <link rel="stylesheet" href="./css/404.css">
  <link rel="stylesheet" href="/_bridgetown/static/css/main.c7d4dd3f1984a290e9be.css" />
  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="80e2efeff4f3f4f2e1f0c0b5aeb3aeb0">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  <link rel="stylesheet" data-purpose="Layout StyleSheet" title="Default" disabled href="/css/app-937c1ff7d52fd6f78dd9322599e2b5d4.css?vsn=d">
  <link rel="stylesheet" data-purpose="Layout StyleSheet" title="Web Awesome" href="/css/app-wa-8d95b745961f6b33ab3aa1b98a45291a.css?vsn=d">

  <link rel="stylesheet" href="https://site-assets.fontawesome.com/releases/v6.4.0/css/all.css">

  <link rel="stylesheet" href="https://site-assets.fontawesome.com/releases/v6.4.0/css/sharp-solid.css">

  <link rel="stylesheet" href="https://site-assets.fontawesome.com/releases/v6.4.0/css/sharp-regular.css">

  <link rel="stylesheet" href="https://site-assets.fontawesome.com/releases/v6.4.0/css/sharp-light.css">
  <link rel="icon" type="image/x-icon" href="/Bootstrap-Technovine/images/favicon-32x32.png">
  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e0c01011a1d1a1c0f1e2e5b405d405e">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>
</head>

<body>
  <!-- 404 CONTENT START -->
  <div class="container" id="error-message">
    <h2>Oops! Page not Found</h2>
    <h1>404</h1>
    <p>Sorry, we can't find the page you are looking for.</p>
    <p>If you clicked a link on our site and were deirected to this page please contact us so we can fix the problem.</p>
    <a href="./index.html">Go back home</a>
  </div>
  <!-- 404 CONTENT CLOSE -->
  <!-- FOOTER SECTION START -->
  <footer class="bg-dark text-white" id="footer">
    <div class="container">
      <div class="row mb-2">
        <div class="col-md-3 mt-5">
          <h4>About Us</h4>
          <hr />
          <p>We are skilled IT professionals who specialize in solving a range of problems that our clients may face in the realm of IT.

          </p>
          <!-- FACEBOOK SECTION -->
          <a href="">
            <i class="fa-brands fa-facebook fa-2x"></i>
          </a>

          <!-- INSTAGRAM SECTION  -->
          <a href="">
            <i class="fa-brands fa-instagram fa-2x"></i>


          </a>

          <!-- TWITTER SECTION -->
          <a href="">
            <i class="fa-brands fa-twitter fa-2x"></i>

            <!-- LINKEDIN SECTION -->
          </a>
          <!-- <a href="#">
                <i class="fa-brands fa-linkedin fa-2x"></i>
              </a> -->

          <!-- WHATSAPP SECTION -->
          <!-- <a href="#">
                <i class="fa-brands fa-whatsapp fa-2x"></i>
              </a> -->

        </div>
        <div class="col-md-3 mt-5">
          <h4>Quick Links</h4>
          <hr />
          <ul class="navbar-nav">
            <li class="nav-item"><a href="/index.html" class="nav-link">Home</a></li>
            <li class="nav-item"><a href="/about.html" class="nav-link">About</a></li>
            <li class="nav-item"><a href="/services.html" class="nav-link">Services</a> </li>
            <li class="nav-item"><a href="/contact.html" class="nav-link">Contact</a> </li>
          </ul>
        </div>

        <div class="col-md-3 mt-5">
          <h4>Privacy and Terms</h4>
          <hr />
          <ul class="navbar-nav">
            <li class="nav-item"><a href="#" class="nav-link">Privacy Policy</a></li>
            <li class="nav-item"><a href="#" class="nav-link">Terms & Coniditions</a></li>
            <li class="nav-item"><a href="#" class="nav-link">API Documentation</a> </li>
          </ul>
        </div>
        <div class="col-md-3 mt-5">
          <h4>Contact Info</h4>
          <hr />
          <p class="text-white">
            city, state 12345 <br /> Call Us Now 123-456-7890 <br />

          </p>
        </div>
      </div>
    </div>
    <div class="bg-dark text-white text-center py-4" id="copyright">
      Copyright &copy; 2023 . All Rights Reserved.
    </div>
  </footer>
  <!-- FOOTER SECTION CLOSE -->
</body>

</html>

This HTML code has been slightly modified with some changes in CSS. Hopefully, these adjustments are helpful.

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

Designing the autocomplete dropdown feature in Bootstrap UI

I'm currently developing an app that is utilizing AngularJS and Bootstrap, with the assistance of Bootstrap UI. Specifically, I am working on implementing the typeahead feature. However, I am facing a challenge in trying to ensure that the dropdown li ...

Stop video and audio playback in an android webview

Is there a way to pause audio and video in an Android WebView without disrupting the page rendering? I have tried various methods but haven't found one that successfully pauses both the sound and the video without affecting the WebView. webView.onPau ...

The placement of buttons in a responsive web design

Need help with adjusting button positions in mobile mode relative to text. Tried using different position settings like absolute and relative, but buttons are not staying aligned with the text on mobile devices. Can anyone assist? .button { display: b ...

Issues with CSS file loading in Django

My program has a CSS file that I defined, but for some reason it's not working. When I checked with firebug, the status is 200 OK, but no changes are occurring. I'm unsure if there is a syntax issue with my CSS file. Can you please provide your i ...

Load HTML content without having to refresh the page

I'm struggling to decide whether I should have the html hidden before it is loaded or pulled from another source. My goal is to display a form on one page and dynamic content on other pages. The form data needs to be saved in mongo db, and when the p ...

Ways to Update/Overwrite Current Information in HTML Using Vue

I have experience creating templates for Vue components using JavaScript. Imagine I have HTML that is generated on the server side with a language called UTL: <table> <tr> <td>[% example_var; %]</td> <t ...

Choosing particular contenteditable divisions using jQuery

Consider the following HTML structure for a specific type of blog post editor: <div class="entry"> <div class="title" contenteditable="true"> <h2>Title goes here</h2> </div> <div class="content" contenteditable ...

What is the process for creating a hover linear wipe transition using CSS/JS?

It's worth noting that I can't simply stack one image on top of the other because I'll be dealing with transparent images as well. preview of linear wipe ...

Adjust the width of a float-right container to its maximum width

Looking for a solution similar to the one discussed in this question: CSS - Float to max width In my project, I am working on a layout that involves a <pic> / <info> style setup, with a twist - I want it to be responsive when the user resizes ...

A linear gradient effect originating from the center/middle of the background

Is it possible to create a linear-gradient background that starts from the center or middle of the screen? This is the CSS I am currently using: body { display: table; width: 100%; height: 100%; margin: 0 auto; background-repeat: no-r ...

Acquiring information to display in a div using innerHTML

I aim to create a div that displays different animal sounds, like: Dog says Bark Bark I've attempted various methods but I'm unable to get each pair in the array to show up in a div: const animal = [ {creature: "Dog", sound: "B ...

Unable to select selectbox in the bottom section of Safari browser

There seems to be an issue with the selectbox being unselectable at the lower part in Safari. It's difficult to pinpoint the exact problem in the code. You can see the issue on the country selectbox by visiting this website: <span> <sp ...

Issue with dynamically adjusting flex box width using JavaScript

Currently, I am developing a user interface that heavily relies on flexbox. The layout consists of a content area and a sidebar that can be toggled by adding or removing a specific class. Whenever the sidebar is toggled, the content area needs to be manua ...

Tips on styling HTML using a query value in string format

When using ASP.NET razor and SQL Server 2008 R2, I have a local variable declared in the following manner: var tsmMtd = db.QueryValue(" SELECT b.Name, SUM(subtotal) totalSUM FROM DR_TRANS a INNER JOIN Staff b ON a.Salesno = b.Staffno WHER ...

The image fails to appear

Check out my website at www.wostokhr.pl I am having trouble getting the picture "pics/hero.jpg" to show up in the "div id="hero"" section with a JS parallax function. I have double-checked the HTML and CSS validators and everything seems to be correct. An ...

Position a component in relation to another component using AngularJS

Utilizing ng-show and ng-hide, I created a descriptive box that appears below text when clicked. However, there is an issue as the description box does not align directly under the text, similar to what is shown in this image https://i.stack.imgur.com/phBh ...

Adding text on top of images for optimal mobile viewing

I'm struggling to ensure that the text stays contained next to the image. It's working fine on desktop and tablet, but I'm facing challenges with mobile. While I have managed to improve it slightly, I can't figure out what exactly I am ...

Unable to view the line number of a CSS style in Chrome Dev Tools while inspecting an element anymore

Today, a strange issue arose that has me puzzled. I can't seem to figure out what caused it. If you take a look at this picture here: This screenshot is from Twitch where I had a tab open. You can see the CSS file and line number displayed as usual. ...

Applying a CSS border to a div that perfectly encloses a span, adjusting to the

My goal is to create a nested structure where a div contains a span element like this: ---------- |Sentence| ---------- ----------------- |It's a looooong| |sentence | ----------------- While it works well for short sentences, long ones end u ...

"Enhance User Interactions with Angular-ui Tooltips Featuring

I recently integrated bootstrap tooltips into my application. While the "normal" tooltips are working fine, I encountered an issue with tooltip-html-unsafe. It seems to display an empty tooltip. Here is my tooltip code: <a><span tooltip-placeme ...