Footer mysteriously appears on top of the container

Trying my hand at practicing HTML by creating a small webpage, but struggling with why the Footer is aligning itself under the Header instead of the container I set up.

It seems like a small detail that I might have missed, but I've hit a wall and can't find a solution anywhere. Any guidance here would be immensely helpful.

header {
  height: 50px;
  width: 900px;
  color: white;
  margin: auto;
  padding: auto;
  background-color: black;
  display: block;
}

nav {
  float: right;
  background-color: black;
}

p,
h1,
h2,
li {
  font-family: sans-serif;
}

footer {
  height: 50px;
  width: 900px;
  color: white;
  margin: auto;
  background-color: black;
  text-align: center;
  padding: auto;
  display: block;
}

main {
  padding: auto;
  display: block;
}

#container {
  display: block;
  padding-bottom: 50px;
  margin: auto;
  width: 900px;
}

#left-column {
  display: inline-block;
  width: 450px;
  float: left;
}

#right-column {
  display: inline-block;
  float: right;
}

#button {
  border-radius: 5px;
  background-color: red;
  text-align: center;
  color: white;
  height: 50px;
  width: 80px;
}
<div id="container">
  <header>
    <p>Logo</p>
    <nav></nav>
  </header>
  <main>
    <div id="left-column">
      <h1>Website title</h1>
      <h2>Article title</h2>
      <p>Some text followed by a list:</p>
      <ul>
        <li>A list item</li>
        <li>A list item with a link (<a href="#">Click me</a>)</li>
        <li>New deals daily</li>
      </ul>
      <p> Some more text</p>
    </div>
    <div id="right-column">
      <h2>Some content related to the article</h2>
      <div id="button">
        <p>A Button</p>
      </div>
    </div>
  </main>
  <footer>
    <p>&copy;Website name 2017</p>
  </footer>
</div>

Answer №1

To ensure your footer does not get affected by floated elements that appear before it, you should include clear:both in your CSS code:

header {
  height: 50px;
  width: 900px;
  color: white;
  margin: auto;
  padding: auto;
  background-color: black;
  display: block;
}

nav {
  float: right;
  background-color: black;
}

p,
h1,
h2,
li {
  font-family: sans-serif;
}

footer {
  height: 50px;
  width: 900px;
  color: white;
  margin: auto;
  background-color: black;
  text-align: center;
  padding: auto;
  display: block;
  clear:both;
}

main {
  padding: auto;
  display: block;
}

#container {
  display: block;
  padding-bottom: 50px;
  margin: auto;
  width: 900px;
}

#left-column {
  display: inline-block;
  width: 450px;
  float: left;
}

#right-column {
  display: inline-block;
  float: right;
}

#button {
  border-radius: 5px;
  background-color: red;
  text-align: center;
  color: white;
  height: 50px;
  width: 80px;
}
<div id="container">
  <header>
    <p>Logo</p>
    <nav></nav>
  </header>
  <main>
    <div id="left-column">
      <h1>Website title</h1>
      <h2>Article title</h2>
      <p>Some text followed by a list:</p>
      <ul>
        <li>A list item</li>
        <li>A list item with a link (<a href="#">Click me</a>)</li>
        <li>New deals daily</li>
      </ul>
      <p> Some more text</p>
    </div>
    <div id="right-column">
      <h2>Some content related to the article</h2>
      <div id="button">
        <p>A Button</p>
      </div>
    </div>
  </main>
  <footer>
    <p>&copy;Website name 2017</p>
  </footer>
</div>

Answer №2

header {
  height: 50px;
  color: white;
  margin: auto;
  padding: auto;
  background-color: black;
  display: block;
}

nav {
  float: right;
  background-color: black;
}

p,
h1,
h2,
li {
  font-family: sans-serif;
}

footer {
  height: 50px;
  color: white;
  margin: auto;
  background-color: black;
  text-align: center;
  padding: auto;
  display: block;

}

main {
  padding: auto;
  display: block;
  overflow:hidden;
}

#container {
  display: block;
  padding-bottom: 50px;
  margin: auto;
  width: 900px;
}

#left-column {
  display: inline-block;
  width: 450px;
  float: left;
}

#right-column {
  display: inline-block;
  float: right;
}

#button {
  border-radius: 5px;
  background-color: red;
  text-align: center;
  color: white;
  height: 50px;
  width: 80px;
}
<div id="container">
  <header>
    <p>Logo</p>
    <nav></nav>
  </header>
  <main>
    <div id="left-column">
      <h1>Website title</h1>
      <h2>Article title</h2>
      <p>Some text followed by a list:</p>
      <ul>
        <li>A list item</li>
        <li>A list item with a link (<a href="#">Click me</a>)</li>
        <li>New deals daily</li>
      </ul>
      <p> Some more text</p>
    </div>
    <div id="right-column">
      <h2>Some content related to the article</h2>
      <div id="button">
        <p>A Button</p>
      </div>
    </div>
  </main>
  <footer>
    <p>&copy;Website name 2017</p>
  </footer>
</div>

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

Using jquery to toggle active nav links in Bootstrap

I'm currently working on integrating a jQuery function to automatically update the active status of the navigation links in my Bootstrap Navbar. The structure involves a base HTML file that extends into an app-specific base file, which is further exte ...

Developing a Java applet for the purpose of showcasing it in a web browser

As I embark on the journey of creating a basic Java applet to showcase my program's output in a web browser, I find myself facing unfamiliar territory. To gain a grasp on how applets function, I decided to follow a tutorial and create a simple "Hello ...

Ways to extract dropdown selection into a .php script

I am trying to capture the selected dropdown value in my .php file, which is used for sending emails. When a user selects one of the 6 options from the dropdown menu, I want that selected option to be included as the email subject. Below is the HTML code ...

When attempting to incorporate the "active" class into a Bootstrap 4 carousel using jQuery, issues arise specifically when retrieving data from a MongoDB database

I'm working on a carousel feature where I need to load images from my MongoDB database. However, the issue I'm facing is that even though I've tried adding the active class to the first item, the carousel doesn't transition to display t ...

.htacces Disables Styling on Page

I've been trying to understand the functionality of .htaccess RewriteRule. Here is a URL example where I have experimented with .htaccess: http://example.com/test/home This used to be: http://example.com/test/index.php?p=1 My goal is to redirect ...

Decreasing the vertical size of the page

My mobile page was meant to be all black, but it's only half black now. I tried the following CSS: @media (max-width: 768px) {body, html.page-id- 28{background-color: black! important;}} @media (max-width: 768px) {. parallax-window {background ...

The appearance of the pop-up mask is displayed at lightning speed

Check out the demo here Here is the HTML code: <div class="x"> </div> <input class="clickMe" type="button" value="ClickMe"></input> This is the JS code: $(".clickMe").click( function() { ...

Guide to adding checkbox IDs and inserting them into a textarea

Hello, my name is Prasath and I am currently learning about AJAX. I am working on a project involving seat layouts and finding it challenging to retrieve both the seat fare and seat number simultaneously. Is there anyone who can assist me in resolving this ...

What is the best way to split an input field into distinct fields for display on the screen?

Take a look at this image: https://i.stack.imgur.com/LoVqe.png I am interested in creating a design similar to the one shown in the image, where a 4 digit one-time password (OTP) is entered by the user. Currently, I have achieved this by using 4 separate ...

Submitting forms using Jquery Mobile

Hi there! I need some assistance with a form that I have created for use with phonegap. I was initially using JavaScript to process it, but now I'm considering switching to jQuery for better functionality. My main goal is to display the "total" in a n ...

Enhance your website with a unique hover and left-click style inspired by the functionality of file explorer

I have a set of items like this: I am trying to replicate the functionality of a file explorer in terms of item selection. To clarify, I aim to create a feature where hovering over an item and left-clicking it would generate a virtual rectangle to select ...

The canvas game's animation can only be activated one time

I am currently working on designing a straightforward canvas game: Here is the code snippet located on CodePen var canvas; var ctx; var x = 300; var y = 400; var r = 0; var mx = 0; var my = 0; var WIDTH = 600; var HEIGHT = 400; function circle(x,y,r) ...

How come my picture is clinging to the bottom of the container?

I am facing an issue where my "vertical rule" is sticking to the bottom of the container when placed to the right of the image. <div> <div style="display:inline-block; width:210px;"> <img src="res/img/PlayBtn.png" style="top:- ...

Discovering the values within a separate JSON object

I have a collection of json objects that include information about different languages and user details. Languages User Details The user details contain a field for languages, which can have multiple values. Below is a sample json: $scope.languages = ...

Clicking on the element will not cause the body to scroll

For some reason, I need to keep the onclick function, but I'm struggling to make it work as intended. What I want is for the body to slide to the next logo when the previous logo is clicked. This is a simplified version of what I have: <div class ...

Creating a Client-side Web Application with Node.js

As I search for a versatile solution to bundle an HTML5 web application (without server dependencies) into a single executable app using node.js and the Linux terminal on Ubuntu, I have experimented with tools like wkpdftohtml and phantomjs. However, these ...

Access SCSS variable values in Angular HTML or TypeScript files

So, I've been looking into whether it's feasible to utilize the SCSS variable value within HTML or TS in Angular. For instance: Let's say I have a variable called $mdBreakpoint: 992px; stored inside the _variable.scss file. In my HTML cod ...

The navigation bar is failing to display all of the titles

Having trouble with my HTML page. I can only see the first word of the title in the drop-down list. The navigation bar refuses to center despite trying various styles. Below is my CSS code: background-color: #78706e; height: 100%; font-family: Arial; c ...

What could be causing the issue: Unable to locate or read the file: ./styles-variables?

I'm currently following a tutorial on how to create responsive layouts with Bootstrap 4 and Angular 6. You can find the tutorial here. I've reached a point where I need to import styles-variables.scss in my styles file, but I keep encountering t ...

Is there a way to deactivate a button upon clicking and then substitute it with a new button that serves a different purpose in AngularJS?

Is there a way to deactivate a button once clicked and substitute it with another button that performs a different task using AngularJS? Here is the button in question: <button type="submit" class="btn btn-small btn-default" ng-disabled="isteam==0 || ...