Steps to design a footer in an HTML file

Despite extensive research on Google and Stack Overflow, I have been unable to find a solution to my HTML footer dilemma. Numerous questions exist regarding this issue, but the solutions provided either lack clarity or fail when additional elements are added to the page.

I am attempting to create a sticky footer that remains at the bottom of the document. My initial attempt using margin-top: 100px worked until more content was added, causing the footer to extend below the layout border. Switching to position: relative resulted in the footer being fixed in the middle of the page.

Below is my CSS code:

.box {
background-color: white ;
height: 800px ;
width: 600px ;
margin: 0px auto ;
border: 1px solid black ;
}

.header {
    text-align: center ;
    padding-left: 5px ;
}

.navigation {
text-align: center ;
font-size: 16px ;
font-family: verdana ;
}

.content {
font-size: 18px ;
font-family: verdana ;
padding-left: 10px ;
}

.contactForm {
font-size: 16px ;
font-family: verdana ;
}

.footer {
margin-top: 100px ;
text-align: center ;
font-size: 16px ;
font-family: verdana ;
width: 600px ;
height: 50px ;
background-color: #f6f6f6 ;
}

Additionally, here is my HTML code:

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
    <link rel="stylesheet" href="testing.css" type="text/css">
</head>
<body bgcolor="#f6f6f6">
    <div class="box">
        <h3 class="header">My blog</h3>
        <hr/>
    <div class="navigation">
        <a href="#">Home</a>
        <a href="#">Posts</a>
        <a href="#">About</a>
        <a href="#">Contact</a>
    </div>
    <hr/>
    <div class="content">
        <form class="contactForm" action="#" method="post">
            <table>
                <tr><td>Contact</td></tr>
                <tr><td>Name:</td><td><input type="text" name="name"></td></tr>
                <tr><td>E-mail:</td><td><input type="text" name="email"><td></tr>
                <tr><td>Message:</td><td><input type="textarea" name="message"></td></tr>
                <tr><td><input type="submit" name="submit"></td></tr>
            </table>
        </form>
    </div>
    <div class="footer">
        test
    </div>
</body>
</html>

After reviewing various guides and articles with no success, I am frustrated and seeking assistance in creating an effective footer. Any explanations or guidance on positioning the footer correctly would be greatly appreciated.

Answer №1

CSS position:fixed; is the key to keeping elements in place.

.footer{
    position: fixed;
    text-align: center ;
    font-size: 16px ;
    font-family: verdana ;
    width: 600px ;
    height: 50px ;
    background-color: #f6f6f6 ;
}

Fiddle: http://jsfiddle.net/pXBpc/1/

Answer №2

Having an open div tag at the start may be causing complications.

Modify:

<div class="box">
<h3 class="header">My blog</h3>
<hr/>

to

<div class="box">
<h3 class="header">My Blog</h3>
</div> 

If that doesn't resolve the issue, consider enclosing the content in a container. I came across this helpful tutorial explaining how to keep the footer at the bottom of the page using CSS.

Answer №3

.footer {
position:fixed;
bottom:0;
text-align: center ;
font-size: 16px ;
font-family: verdana ;
width: 600px ;
height: 50px ;
background-color: #f6f6f6 ;
}

Answer №4

To ensure your footer stays at the bottom of your webpage, utilize the code snippet below:

.footer {
   position:fixed;
   left:0px;
   bottom:0px;
   height:50px;
   width:100%;//or adjust to 600 pixels if a full-width footer is not desired
   background:#999;
}

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

Gathering information from a website by using BeautifulSoup in Python

When attempting to scrape data from a table using BeautifulSoup, the issue I'm running into is that the scraped data appears as one long string without any spaces or line breaks. How can this be resolved? The code I am currently using to extract text ...

Effortlessly aligning icons in social media buttons using Bootstrap

I am encountering an issue with my social media icons that are using font-awesome icons from Bootstrap. The problem is that the icons are not centered. Here is the code I am using, most of which was copied and pasted from an online source: #HTML <!-- ...

Is it possible to activate a block display for an article based on the class value when a radio

Here is the HTML code snippet I'm working with: <div id="contentapp"> <input type="radio" name="menu" id="interest" checked> <input type="radio" name="menu" id="about"> <div id="tab"> <label for="intere ...

Error icon appearing on Material UI's Stepper Component when not needed

I am currently using the Stepper component from Material UI and attempting to make the fill of a stepper that is in its error state appear red. If you need to see the Stepper component from Material UI's documentation, you can access it https://i.sst ...

Utilize the Window feature to implement a search bar in both JavaScript and HTML

Hey there, I'm currently working on setting up a search bar that can search for any string available on an HTML page. So far, I've been utilizing the window.find method which highlights the string if it's found on the page and returns either ...

Only import the Excel file into the database if it is located within the IIS Express directory

I am currently working on a program that is designed to import data from an Excel file into a SQL Server database. The program seems to be functioning properly when I save the Excel file in the IIS express folder. However, if I try to save it in the docume ...

Revamping Existing Styles: Making a Statement with `:after`

In my asp.net mvc application, I am facing an issue where the * symbol, representing a required field, and the ? symbol, representing help, are not both being displayed. The ? symbol seems to be overriding the * symbol, resulting in only one symbol being s ...

Inserting images into an HTML table using JavaScript in real-time

I am attempting to dynamically add an image into a table, but I am encountering difficulties. Whenever I try to insert an image into a cell, I receive the following error message: Cannot access the inner content because it is not literal. if ...

What steps should be taken to advance a group of students from one semester to the next?

In a scenario where I need to promote multiple students from semester 1 to semester 2 in one go, the current code logic seems to only handle promotion for single students. How can I modify it to accommodate batch promotion? -------------------Controller ...

Tips for achieving a full div image on hover

I'm having trouble with my CSS code for an image hover effect in a div. The image is appearing larger than the div and leaking out of it. How can I make sure the image stays contained within the div? Here's the updated CSS code: img { display ...

Icon displayed within the input field

Is there a simple method to add an input text element with a clear icon on the right side, similar to the layout of the Google search box? I've searched, but I could only find instructions for placing an icon as the background of the input element. I ...

Retrieving selected option value in React

I am currently using Material UI for my React application and I am encountering an issue with getting the value of a select form. Initially, I had success with the following code snippet: <select name="role" value={props.role} onChange={props.handleIn ...

JavaScript offers a variety of options for creating a link-styled button

Is there a distinction between <a href="javascript:;"></a> and <a href="javascript:void(0);"></a> ? I am looking to create a link-styled button that triggers a JavaScript function when clicked, so I implement the following: ...

Adjustable width box with shortened text

My challenge is to arrange 4 divs side by side, with the first two on the left, the fourth on the right, and the third filling the remaining space in between. The third div should have a dynamic width and contain two text lines that should support ellipsis ...

Utilize the Tab key in Textarea fields to insert a tab character ( ) instead of navigating to the

My current issue involves utilizing an HTML textarea named userInput. Whenever I press the tab key, it simply shifts focus to the next element instead of inserting a tab character or some spaces within the textarea. Is there a way for me to configure the ...

State in Angular stubbornly refuses to switch despite condition changes

Here is the Typescript code, followed by the HTML: public verifySelection() { let choice = false; if (typeof this.formUser.permissionsTemplateID === undefined) { choice = true; } return choice; } <div class="form-group" ...

Why is it that the form does not fully appear when the screen is being resized with absolute display?

Utilizing bootstrap columns, I have a form that is set to display: absolute. However, when the screen size is reduced, the form does not appear completely as seen in this image. How can I ensure that the form appears entirely as shown in the desired resul ...

Incorporate New Material into DIV Using a Specific Class Identifier

I need to customize the default output of Wordpress menu using <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>. My goal is to change the appearance of pages with submenus. Currently, pages with a submenu are fo ...

Converting Arabic characters from HTML to PDF with iText

I have thoroughly searched every iText related topic regarding Arabic characters on various platforms, but I have not been able to find a solution for my specific issue. I am trying to convert an HTML file into a PDF, but the HTML content includes both Eng ...

Mastering the art of utilizing clearInterval effectively

This reset button needs to clear/reset the timer. The issue is that when the user presses the start button more than once, it sets two timers - one from the previous start and one from the current start. I will be using clearInterval to solve this problem ...