I am having trouble with the spacing on my website, even after I have tried declaring it

I'm having trouble formatting the footer to appear at the bottom of the page. I've tried adjusting the CSS code for the .container and .footer classes, but nothing seems to work. As a newbie in website development, any helpful tips or suggestions would be appreciated. Here's the HTML and CSS code I'm working with:


<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" type="text/css" href="css/main.css">
  <title> ~ Portfolio</title>
  <meta name="description" content="The HTML5 Herald">
  <meta name="author" content="SitePoint">
</head>

<body>
  <header>
    <div class="container">
      <img src="">
        <nav>
          <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Skills</a></li>
            <li><a href="#">Experience</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </nav>
      </div>
      <footer class="footer">
        <font color="white" face="Roboto">Johnny Handcock</font>
      </footer>
      </header>
</body>
</html>



nav {
word-spacing: 15px;
float: right;
padding-right: 20px;
 /* normal, hidden state */
}
a {
  text-decoration:none;
 color: #ffff;
 font-size: 20px;
 font-family: 'Roboto', sans-serif;
 font-weight: 600;
}
a:hover {
   /* when parent is hovered */
   color:black;
   opacity: 0.6;
   outline-style: solid;
   outline-color: radial-gradient(circle, rgba(128,0,255,1) 0%, rgba(128,0,255,0.9612045501794468) 67%, rgba(102,34,193,1) 84%);
   border-radius: 10px;
}

ul > li {
    display: inline-block;
    /* You can also add some margins here to make it look prettier */
    zoom:1;
    *display:inline;

    /* this fix is needed for IE7- */
}
body {
  /* Previous Config   background: rgb(48,6,102);
  background: linear-gradient(117deg, rgba(48,6,102,1) 0%, rgba(110,5,162,0.9612045501794468) 56%, rgba(109,32,210,1) 77%);*/
  background: rgb(128,0,255);
  background: radial-gradient(circle, rgba(128,0,255,1) 0%, rgba(128,0,255,0.9612045501794468) 67%, rgba(102,34,193,1) 84%);
  /* Top, Right, Bottom, Left
  margin: 400px 300px 200px 800px */
}
.footer {
  background-color: #111111;
    color: #eeeeee;
    border-top: 1px solid red;
    height: 60px;  /* footer height */
    padding-top: 20px;
    display: block;
    margin-top: 20px; /* space between content and footer */
    box-sizing: border-box;
    position: relative;
    width: 100%;
}

Answer №1

The placement of the footer within the header seems a bit off, but it could be intentional. If you are facing the "sticky footer" issue, you may want to consider using flexbox as a solution. Here is a simple implementation:

body {
   margin: 0;
}

html, body, header {
    height: 100%;
}

header {
    display: flex;
    flex-direction: column;
}

footer {
    margin-top: auto;
}

To achieve this, make the container div for the footer display as flex with a column direction, and set a margin-top of auto for the footer element. Also, ensure that html, body, and the flex container have a height of 100%:

nav {
  word-spacing: 15px;
  float: right;
  padding-right: 20px;
  /* normal, hidden state */
}

a {
  text-decoration: none;
  color: #ffff;
  font-size: 20px;
  font-family: 'Roboto', sans-serif;
  font-weight: 600;
}

a:hover {
  /* when parent is hovered */
  color: black;
  opacity: 0.6;
  outline-style: solid;
  outline-color: radial-gradient(circle, rgba(128, 0, 255, 1) 0%, rgba(128, 0, 255, 0.9612045501794468) 67%, rgba(102, 34, 193, 1) 84%);
  border-radius: 10px;
}

ul>li {
  display: inline-block;
  /* You can also add some margins here to make it look prettier */
  zoom: 1;
  *display: inline;
  /* this fix is needed for IE7- */
}

body {
  background: rgb(128, 0, 255);
  background: radial-gradient(circle, rgba(128, 0, 255, 1) 0%, rgba(128, 0, 255, 0.9612045501794468) 67%, rgba(102, 34, 193, 1) 84%);
}

.footer {
  background-color: #111111;
  color: #eeeeee;
  border-top: 1px solid red;
  height: 60px;
  padding-top: 20px;
  display: block;
  box-sizing: border-box;
  position: relative;
  width: 100%;
}

body {
   margin: 0;
}

html, body, header {
    height: 100%;
}

header {
    display: flex;
    flex-direction: column;
}

footer {
    margin-top: auto;
}
<header>
  <div class="container">
    <img src="">
    <nav>
      <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">Skills</a></li>
        <li><a href="#">Experience</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </nav>
  </div>
  <footer class="footer">
    <font color="white" face="Roboto">Johnny Handcock</font>
  </footer>
</header>

Answer №2

nav {
word-spacing: 15px;
float: right;
padding-right: 20px;
 /* normal, hidden state */
}
a {
  text-decoration:none;
 color: #ffff;
 font-size: 20px;
 font-family: 'Roboto', sans-serif;
 font-weight: 600;
}
a:hover {
   /* when parent is hovered */
   color:black;
   opacity: 0.6;
   outline-style: solid;
   outline-color: radial-gradient(circle, rgba(128,0,255,1) 0%, rgba(128,0,255,0.9612045501794468) 67%, rgba(102,34,193,1) 84%);
   border-radius: 10px;
}

ul > li {
    display: inline-block;
    /* You can also add some margins here to make it look prettier */
    zoom:1;
    *display:inline;

    /* this fix is needed for IE7- */
}
body {
  /* Previous Config   background: rgb(48,6,102);
  background: linear-gradient(117deg, rgba(48,6,102,1) 0%, rgba(110,5,162,0.9612045501794468) 56%, rgba(109,32,210,1) 77%);*/
  background: rgb(128,0,255);
  background: radial-gradient(circle, rgba(128,0,255,1) 0%, rgba(128,0,255,0.9612045501794468) 67%, rgba(102,34,193,1) 84%);
  /* Top, Right, Bottom, Left
  margin: 400px 300px 200px 800px */
  margin:0;
}
.footer {
  background-color: #111111;
    color: #eeeeee;
    border-top: 1px solid red;
    height: 60px;  /* footer height */
    padding-top: 20px;
    padding-left:20px;
    display: block;
    margin-top: 20px; /* space between content and footer */
    box-sizing: border-box;
    
    width: 100vw;
    
    position:absolute;
    bottom:0;
   
}
<html lang="en">
<head>
  <meta charset="utf-8>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" type="text/css" href="css/main.css">
  <title> ~ Portfolio</title>
  <meta name="description" content="The HTML5 Herald">
  <meta name="author" content="SitePoint">
</head>

<body>
  <header>
    <div class="container">
      <img src="">
        <nav>
          <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Skills</a></li>
            <li><a href="#">Experience</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </nav>
      </div>
      <footer class="footer">
        <font color="white" face="Roboto">Johnny Handcock</font>
      </footer>
      
      </header>
      
</body>
</html>

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

checkbox causing the button to appear empty

Due to the inability of a ngIf and ngFor to coexist, I added an ng-container to facilitate the loop. However, after making this change, nothing seems to be working as expected without any clear reason. Below is the code snippet that is causing trouble: Vi ...

Looking for a logo placed in the center with a top fixed navigation using Bootstrap

I am in need of a Centered Logo using Bootstrap fixed top navigation. The goal is to have the brand centered within the navigation. Check out my Sample Fiddle .LandPageNavLinks { list-style-type:none; margin:0; padding:0; } .LandPageNavLin ...

The three.js library is throwing an error because it is unable to access the 'geometry' property of an

function CreateNewSphere(x, z) { var sphereGeometry = new THREE.SphereBufferGeometry(10 * factor, 32, 32); var sphereMaterial = new THREE.MeshBasicMaterial({ color: SphereColor, wireframe: false }); var sphere = new THRE ...

Explore the latest update in the AngularJS single page application that introduces a new feature specifically designed for the initial login

Our AngularJS single page application has a new feature that we are ready to launch for customer use. We want to inform the logged in user about this new feature so they can start using it. We are looking for a small animated information symbol with a too ...

What steps can I take to display lines in a textarea so that it closely resembles the appearance of a notepad document

Is there a way to display lines in a text-area to give it the appearance of a notepad? I only have one text-area available. See the example notepad below for reference. ...

Retrieving HTML content from an AJAX request

Is it possible to query HTML data returned from an AJAX request? I attempted the following code: $.post("gethtml.php", { url: $url.val() }, function(data) { var $html = $(data), $links = $("link, script, style", $html), $body ...

Text that spans across multiple lines

I have a multi-line text that I need to adapt to a div. For example: https://i.stack.imgur.com/mtZmf.png Is there a way to adjust the text within the div? Can we prevent the blue spacing after the word "text" using CSS? If I have various texts of differ ...

A guide on changing the style of a Layout component in React

Currently, I am utilizing Next.js alongside Material-UI as the framework of choice. Within my project, there is a Layout component that encapsulates the content with Material-UI's <Container>. I desire to customize the style of the Layout compon ...

Vue 2 does not properly transition the initial element when using the `mode=out-in` attribute

In my Vue project, I am using version 2.6.14 and trying to toggle between two buttons by utilizing v-if and v-else. Despite wrapping everything in a transition element, the first button doesn't transition smoothly, neither when appearing nor disappear ...

Unable to navigate through select2 dropdown if fixed div is present

I am facing an issue with select2 in my fixed div popup that acts like a modal. The problem is that when the select2 dropdown is open, I am unable to scroll the div until I close the dropdown. This becomes problematic on smartphones because the keyboard e ...

Setting up ng-show in AngularJS

Looking for a solution to use ng-repeat and ng-show to organize data into two columns effectively <div class="col-md-4"> <div class="row" infinite-scroll="eventSearchService.getMoreEvents()"> <div ng-repeat="event in eventSearchService ...

Tips for maintaining consistent styles in CSS for multiple websites

I am currently working on developing a customizable chatbot widget using react. The goal is to create a chatbot widget that can be easily integrated into any website, similar to the functionality of rasa-webchat. During testing on some websites, I encount ...

How can I apply and delete a css class only while scrolling in a React application?

Currently, I am designing a pretend blog layout to showcase my work. The grid of posts features cards that are precisely 400x400 in size with a hover effect that magnifies and adds a drop shadow (this is visible in the dashboard route). However, an issue ...

Incorrect Alignment of Centered Boxes with CSS

I'm having trouble creating centered boxes with CSS. Currently, I have the following code: http://jsfiddle.net/LW7mN/2/ .trex-clear-all{ display: inline-block; width: 99%; height: 17px; font-size: 12px !important; text-align: -w ...

It is not possible to submit a form within a Modal using React Semantic UI

I am working on creating a modal for submitting a form using React semantic UI. However, I am encountering an issue with the submit button not functioning correctly and the answers not being submitted to Google Form even though I have included action={GO ...

Adjusting height in CSS can be done dynamically based on the content within

Currently, I am working on a project where I need the submenu to adjust based on content. The issue is that right now, the submenu has a fixed capacity of 4 items. For example, when you click on 'sale', it displays 4 submenu items perfectly. Howe ...

Is there a way for me to display the image name at the bottom before uploading it, and have a new div created every time I upload an image?

Is there a way to display the image name at the bottom and have it create a new div every time an image is uploaded? I would appreciate any help with this... <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstra ...

I am having issues with my CSS file not functioning correctly on my Django template. Does anyone have any suggestions on how to resolve this issue

I've encountered issues with CSS files not working properly on my Django template. Whenever I make changes to the CSS file and reload the browser page, nothing happens. However, if I restart my computer or power off and on again, the changes reflect o ...

What causes loss of focus in a React input element when it is nested inside a component?

When I have an input element connected to the React Context API, updating the value onChange works fine when the element is not nested within a component. However, if I render a different component just under the input that returns another input field conn ...

How can I retrieve the URL for a specific location on Google Maps using latitude and longitude coordinates?

Is it possible to generate a URL using latitude and longitude coordinates that will take me directly to a Google Maps page showing that location? For instance, consider the following sample code: var lat = 43.23; var lng = 114.08; var url = 'http:/ ...