A common challenge of aligning divs in the center and creating a persistent footer

I am in the process of creating an HTML5 page that has a centrally aligned wrap div and a sticky footer. Below is the HTML code I am using:

<body>
  <div id="wrapper">
    wrapper
  </div>
  <footer>
    this is footer
  </footer>
</body>

Here is the CSS code I have implemented:

#wrapper {
width:800px;
height:100%;
padding:5px;
margin:0 auto;
background-color:#fff;
border-radius:10px 10px 0 0;
box-shadow:0 1px 10px 3px #666;
}

footer {
background-color:#060318;
color:#3cc9e7;
width:800px;
padding:5px;
position:fixed;
bottom:0;
}

However, when I view the result, the elements are not centered as intended.

How can I ensure both the wrap div and the footer are centered properly, with the footer being sticky?

Answer №1

While there may be other solutions, one option is to place a div in the footer and center it using CSS:

<footer>
    <div>this is the footer</div>
</footer>

Here is the corresponding CSS for this setup:

footer {
    position:fixed;
    bottom:0;
    left: 0;
    right: 0
}

footer div {
    background-color:#060318;
    color:#3cc9e7;
    width:800px;
    padding:5px;
    margin:0 auto;
}

You can view the outcome of this solution on JSFiddle: http://jsfiddle.net/xRzQy/

Answer №2

position: fixed behaves similarly to position: absolute. To center it, you have two options: utilize JavaScript or introduce a wrapper element:

<div id="footersurround">
  <footer>
    This is the footer content
  </footer>
</div>​

CSS:

#footersurround {
    width: 100%;
    position: fixed;
    bottom: 0;
}
footer {
    background-color:#060318;
    color:#3cc9e7;
    width:800px;
    padding:5px;
    margin: 0 auto;
}​

http://jsfiddle.net/mblase75/ABCDE/

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

Guide to dynamically add data to two columns

I have a challenge with organizing multiple inputs into rows with two columns each, ensuring that each input is appended to the appropriate side (50% for each column unless there's an odd number of inputs). Currently, the inputs are being added to se ...

What is preventing me from accessing the hidden article using the URL with the hashname?

I've been searching for a solution, but so far nothing seems to work for me. I have a page with header and content sections. The content section is currently not visible. When I click on an item in the navigation menu, I want to hide the header and di ...

Modifying Bootstrap image dimensions

I've been working on creating a card div with two images inside: an up arrow and a down arrow. Everything looks good when the page is in full screen mode, with the images displaying at their full size. However, with Bootstrap's responsive design ...

Designing a unique 24-column grid system for Bootstrap 4

I'm working on a project and looking to incorporate some bootstrap elements into my HTML files for UI development. My goal is to modify the standard grid size from 12 to 24. I've read through the documentation, but I'm unsure of where exactl ...

What is the best way to save website information in SQL Server?

My website is www dot abc dot com and it contains some valuable content that I want to store in SQL Server. Can this be done using DOM? If not, please recommend alternative methods. I've searched this forum for similar solutions but haven't found ...

Firefoxi is the only browser that exhibits strange padding and margin behavior

Check out this webpage at: www.bit.ly/1b4dUqs Most browsers display the page correctly, but there seems to be an issue with Firefox's (latest version) handling of margin-top/padding-top styles. If anyone has a solution for this problem, please share ...

Which one has better performance: class or CssClass?

Curious about the efficiency of: <asp:TextBox runat="server" class="someCssClass"></asp:TextBox> as opposed to. <asp:TextBox runat="server" CssClass="someCssClass"></asp:TextBox> I speculate that class is quicker than CssClass s ...

The anchor hover state will persist even after clicking the link

What if I need to create navigation top menu buttons with anchor tags, each having a specified href? I've already styled the hover effect for each button, but when I click on a link, the hover effect disappears. How can I ensure that the hover effect ...

Is there a workaround for retrieving a value when using .css('top') in IE and Safari, which defaults to 'auto' if no explicit top value is set?

My [element] is positioned absolutely with a left property set to -9999px in the CSS. The top property has not been set intentionally to keep the element in the DOM but out of the document flow. Upon calling [element].css('top') in jQuery, Firef ...

What are the steps for integrating a CMS with my unique website design?

Currently, I am in the process of creating a unique website for a client using my own combination of html, css, and JavaScript. There is also a possibility that I may incorporate vueJS into the design. The client has expressed a desire to have the ability ...

Conceal Content from Onsite Search

Is it possible to conceal text from on-page browser searches (e.g. Ctrl+F) in a dependable manner while keeping it visible? I thought that adding aria-hidden="true" would address the issue, but the text remains searchable by browsers. ...

What method is being used by this website to carry out this specific task?

I recently came across this website, , and I was intrigued by the functionality of the matrix entry feature. By clicking on the bracket icon next to the H2O icon, you can access it. Upon accessing the matrix entry function, users are prompted to input th ...

Looking to insert an image in the top-left corner of a div?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> <head> <script src="http://ajax.googleapis.com/ajax/libs/jq ...

When resizing the browser, HTML/CSS elements tend to shift positions :(

I've experimented with different position values like absolute, fixed, and static without success. Wrapping the element in a div didn't yield the desired result, so I'm seeking assistance to correct this. (If that is the solution) The issu ...

Ways to optimize the spacing between the menu bar and widgets

I have successfully incorporated multiple images side by side on my blog Following is the code used for this layout: <div class="images"> <figure> <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSA7XLfGrT1rMS-Ifoguz-X2igsT ...

Bootstrap 4 grid system: mixed column widths with fixed and variable, may experience overlapping in IE11"

Dealing with Bootstrap 4 grid challenge in IE11 when using a fixed width column I am working on a three-column grid where the middle column needs to have a fixed width, while the left and right columns are flexible/wrappable. Here is the code snippet I h ...

Using onClick function to pass the value of an input textbox in PHP

I have an input text field and I am looking to pass the values entered inside the element through a JavaScript onClick event. <form> <fieldset> <label>Common Site ID: </label><span><?php echo $commonsiteid ?>< ...

``I am experiencing difficulties with utilizing a personalized color scheme in React JS with Material

I'm currently working on customizing the color palette for my project, but I am only able to modify the main attribute and not others. My development environment is JavaScript with MUI, not Typescript. import './App.css'; import {BrowserRout ...

Guiding the way with headings listed beneath every point

Hello there! I am trying to achieve a specific layout using this image as a reference. In the image, there are 3 different background images (represented by three Divs) and I want to add 3 List Points labeled as "LV", "RP", "IP" with centered descriptions ...

Exploring the Ways to Perform Mathematical Operations in HTML

I would like to display the percentage, but I am receiving values like 14.00 The expected value is 56%. 14 represents 56% of 25. Sample code: <h2>(@Model[1].filled.ToString("N2"))</h2> ...