Html5 - Placing the footer on top of the main content to create a unique design

Here is the HTML code snippet I am currently working on:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width = device-width">
    <meta name="description" content="Some training on web design">
    <meta name="keywords" content="web, design">
    <meta name="author" content="Houssem badri">
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/style.css">
    <script src="js/script.js"></script>
    <title>My Web design | Welcome</title>
  </head>
  <body>
      <header>
        <div class="branding">
          <h1>Some title</h1>
        </div>
        <nav>
          <ul>
            <li><a href="#">Contact us</a></li>
            <li><a href="#">About us</a></li>
            <li><a href="#">Services</a></li>
            <li><a class="current" href="#">Home</a></li>
          </ul>
        </nav>
      </header>
        <div  class="left-col">
          <section>
            <article>
              <h1>My first article</h1>
              <p>Some Text</p>
            </article>
            <article>
              <h1>My Second article</h1>
              <p>Some Text</p>
            </article>
          </section>
        </div>
        <div class="mid-col">
          <section>
            <h1> Main section title </h1>
            <p>Some Text</p>
          </section>
        </div>
      <aside role="complementary">
        <h1>Aside title</h1>
        <p> Some text </p>
      </aside>
      <footer>
          <h4>Copyright&copy <a href="#">blabla.com</a></h4>
      </footer>
  </body>
  </html>

I also have a CSS file for styling purposes, which includes the following styles:

/* Global */

body{
    background: #E1F9A8;
    font-family: "Arial";
    font-size: 16px;
    width: 80%;
    margin: auto;
    overflow: hidden;
    padding-bottom:60px;
}
ul{
    margin:0;
    padding:0;
}

/* Header */
header{
    border: 1px solid;
    border-radius: 10px;
    background-color: #D0D8BE;
    min-height: 75px;
    padding-top:30px;
    margin-top: 20px;
}
header nav{
    margin-top:10px;
}
...

Upon viewing the output of my code, I noticed overlapping elements. I suspect that my HTML structure may not be correct. Here is an image showing the issue:

https://i.sstatic.net/WrPJV.png

Answer №1

To ensure proper alignment of the footer with floating elements above, include clear: both in the footer's CSS.

Remove overflow: hidden from the body tag.

body{
    background: #E1F9A8;
    font-family: "Arial";
    font-size: 16px;
    width: 80%;
    margin: auto;
    padding-bottom:60px;
}
ul{
    margin:0;
    padding:0;
}

/* CSS Styles */
header{
    border: 1px solid;
    border-radius: 10px;
    background-color: #D0D8BE
    ...
}
...
footer{
    border: 1px solid;
    border-radius: 10px;
    background-color: #D0D8BE;
    padding:20px;
    margin:20px 0 0 20px;
    clear: both; /* Include this for correct alignment */
}
<!DOCTYPE html>
<html>
  <head>
  ...
  </head>
  <body>
      <header>
        ...    
      </header>
        
        <div  class="left-col">
          ...
        </div>
        <div class="mid-col">
          ...
        </div>
      <aside role="complementary">
        ...
      </aside>
      
      <footer>
          <h4>Copyright&copy <a href="#">blabla.com</a></h4>
      </footer>
  </body>
  </html>

Answer №2

Create a class named clearfix in CSS to clear the ends when dealing with floating child divs. Apply this class to the parent div wherever needed.

.body{
    background: #E1F9A8;
    font-family: "Arial";
    font-size: 16px;
    width: 80%;
    margin: auto;
    overflow: hidden;
    padding-bottom:60px;
}
ul{
    margin:0;
    padding:0;
}

/* Header */
header{
    border: 1px solid;
    border-radius: 10px;
    background-color: #D0D8BE;
    min-height: 75px;
    padding-top:30px;
    margin-top: 20px;
}
header nav{
    margin-top:10px;
}
header li{
    float: right;
    padding: 0 10px 10px 0;
    display: inline;
}
header a {
    text-decoration: none;
    text-transform: uppercase;
    color: #226B90;
    font-weight: bold;
}
header .branding{
    float: left;
    margin: 0 0 35px 10px;
    /* Some design */
    text-shadow: 1px 1px 2px orange;
}
header .branding h1{
    margin:0;
}
header .current, header a:hover{
    color: #C48B19;
    text-shadow: 1px 1px 2px orange;
}

/* Left side */
.left-col {
    width: 26%;
    float: left;
    border: 1px solid;
    border-radius: 10px;
    overflow: hidden;
    margin-top: 10px;
    background-color: #FAF8F3;
    margin-right: 12px;
}
.left-col  h1{
    padding-left: 10px;
}
.left-col  p{
    padding-left: 10px;
}
.left-col  i{
    padding-left: 10px;
}
.left-col  .read-more{
    color: #C48B19;
    text-shadow: 1px 1px 2px orange;
    float: right;
    text-decoration: none;
}

/* Right side */
aside{
    width: 25%;
    float: left;
    border: 1px solid;
    border-radius: 10px;
    overflow: hidden;
    margin-top: 10px;
    background-color: #FAF8F3;
}
aside h1{
    padding-left: 10px;
}
aside form{
    padding: 0 10px 10px 10px;
}

/* Main section */
.mid-col{
    width: 46%;
    border: 1px solid;
    border-radius: 10px;
    overflow: hidden;
    margin-top: 10px;
    background-color: #FAF8F3;
    float: left;
    margin-right: 12px;
}

.mid-col h1, .mid-col h2, .mid-col img, .mid-col p{
    padding-left: 10px;
}
.mid-col img{
    width: 96%;
}

/* footer */
footer{
    border: 1px solid;
    border-radius: 10px;
    background-color: #D0D8BE;
    padding:20px;
    margin:20px 0 0 20px;
}

.clearfix:before, .clearfix:after { 
  display: table; 
  content: " ";
}
.clearfix:after { 
  clear: both;
}
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width = device-width">
    <meta name="description" content="Some training on web design">
    <meta name="keywords" content="web, design">
    <meta name="author" content="Houssem badri">
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/style.css">
    <script src="js/script.js"></script>
    <title>My Web design | Welcome</title>
  </head>
  <body>
      <header>
        <div class="branding">
          <h1>Some title</h1>
        </div>
        <nav>
          <ul>
        
        <li><a href="#">Contact us</a></li>
            <li><a href="#">About us</a></li>
            <li><a href="#">Services</a></li>
            <li><a class="current" href="#">Home</a></li>
          </ul>
        </nav>
      </header>
        <div class="clearfix">
        
        <div  class="left-col">
          <section>
            <article>
              <h1>My first article</h1>
              <p>Some Text</p>
            </article>
            <article>
              <h1>My Second article</h1>
              <p>Some Text</p>
            </article>
          </section>
        </div>
        <div class="mid-col">
          <section>
            <h1> Main section title </h1>
            <p>Some Text</p>
          </section>
        </div>
      <aside role="complementary">
        <h1>Aside title</h1>
        <p> Some text </p>
      </aside>
      
        </div>
      <footer>
          <h4>Copyright&copy <a href="#">blabla.com</a></h4>
      </footer>
  </body>
  </html>

Answer №3

I have tested out your code and it looks great, but I recommend adding a small snippet to the footer section in the CSS file. Take a look at the code below for the footer styling:

<!-- Footer Styling -->
<style>
  footer {
    border: 1px solid;
    border-radius: 10px;
    background-color: #D0D8BE;
    padding: 20px;
    margin: 15px 0 0 0px;
    clear: both;
  }
</style>

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

Why is it that the z-index doesn't seem to affect the stacking order of my background image?

I am facing an issue with my Bootstrap carousel where the z-index is not working as expected. The decoration I have in the background is overlapping the text instead of appearing behind it. I want the illustration to be positioned under the text. .carou ...

What is the best way to display sanitized text on a webpage?

I have implemented express-validator in my project to sanitize and escape user input before saving it to my MongoDB database. However, when I try to store a URL in the database after sanitizing it, it gets stored as: https:&#x2F;&#x2F;www.youtube. ...

Excessive white space on WordPress pages is creating a less than ideal

On my WordPress page, I have set up a row with the main side at span10 and the right sidebar at span2. However, the layout leaves too much blank space, causing users to scroll to the right and see nothing. You can view the specific page here Below is the ...

Python code snippet for transforming JSON data into an HTML table

Recently, I've been utilizing the JSON library in Python to extract data from JSON files through Python. extractedData = json.loads(jsonfile) While I have a solid grasp on handling JSON files with Python, I am now exploring ways to present JSON data ...

CSS navigation not working properly in Internet Explorer 7

I am struggling to get this script to function properly in IE 7, as the navigation menu is CSS3-based and breaks completely after using Modernizer. Check out an example on this fiddle Modernizer did not fix the problem, so I'm considering if I need ...

Showing information in <select> depending on the selection of another <select>

I am working on a form that includes two drop down menus. My goal is to dynamically create an SQL query based on the option selected in the first drop down menu, retrieve relevant data from the database, and display it in the second drop down menu. Here i ...

Tips for aligning Picture boxes using CSS

As a newbie, I recently received training in HTML, CSS, and a bit of JavaScript. Currently, I am involved in a project where I display the latest news from an API. The technical aspects of fetching data from the API using JavaScript are handled by a senior ...

Learn the steps for accessing and utilizing aria-label text in Google Chrome

Struggling with the aria-label attribute for blind users in Chrome. Can't seem to hear the aria-label text. Any insights on how aria-label behaves in Chrome or if I'm using the wrong approach? If I'm heading in the wrong direction or using ...

I'm facing an issue where the Font Awesome icons are not appearing in my code

I'm seeking assistance with my code as I develop a website and have encountered a roadblock at the very beginning. Despite following a tutorial, I expect two icons to be displayed in the window but instead, all I see is a blank white screen. <! ...

Create a search bar using HTML and CSS that utilizes the GET method

My current challenge involves creating a search functionality using HTML based on the username entered, such as 'user'. Upon clicking the search bar, the page should redirect to http://localhost/searchuser/user I am encountering difficulties wi ...

Ways to maximize the usefulness of input[type=number] for obtaining authentic value

When using input[type=number], I noticed that Chrome allows users to type not only numbers, but also special characters like the minus sign (-) for negative numbers. Surprisingly, it even permits multiple instances of these characters, such as ".....---888 ...

The Javascript file seems to be unable to recognize the reference to an Angular directive

When working on my project, I encountered an issue with my EventController.js not recognizing the reference to ng-app="eventsApp" from app.js. I followed a tutorial on Pluralsight. Even though it works for the instructor, I keep seeing {{event.name}} inst ...

What is the best way to retrieve the value of an element enclosed within a tag?

<div class="player__AAtt"> <div> <play-js data-account="1234567890" data-id="32667_32797"> </play-js> </div> </div> Is there a way to extract the values of data attr ...

Set the style properties of one class to match the style properties of another class using JavaScript

I need to dynamically create a div using the Bootstrap panel for displaying it. The div's class will either be "panel panel-success" or "panel panel-danger" based on the server response, which can be either "success" or "failure." To assign the class ...

Browser Fails to Recognize AJAX Links as Visited

It appears that the styles for a:visited do not apply to links that are loaded via JavaScript. When a user clicks on a standard link, it shows as visited right away and even after refreshing the page. I'm uncertain if this issue is specific to jQuery ...

Manipulating and targeting specific elements inside a div using jQuery

I am attempting to target and style all instances of the "picture" element nested inside any divs with a class of "highlights". Below is an excerpt from a webpage showcasing the picture element within a "highlights" div... <div class="row highlights"&g ...

Tips for changing the color and incorporating text into an image

Hey there! I'm interested in creating a website where users can select colors like blue, white, and black without the page reloading. Once a color is selected, users should have the option to add text on top of the color image, as well as the option t ...

Peek into the Outlook Calendar Event's Source Code

We are interested in analyzing the source code of calendar events in Outlook across all versions from 2010 to 2016 due to its integration with multiple platforms like Google, Exchange, and Exchange Online. Is there a method available to obtain the HTML so ...

Successfully executing complex designs using CSS grid or flexbox

I have a specific responsive layout that I need to achieve using a series of div tags. Below is the HTML structure I have: <div class="container"> <div>1</id> <div>2</id> <div>3</id> <div>4& ...

Is it possible to utilize an Angularjs service as a means for transferring data between controllers?

After experimenting with this example to facilitate data transfer between two different controllers in AngularJs, I am encountering an issue. While I can modify a variable of the service from the second controller and display it in its view, the change doe ...