What is causing my table to refuse to center?

I'm having trouble keeping my table of images contained within the content area of my page. Additionally, I can't seem to get my footer to stay at the bottom of the page. Take a look at this image for reference:

body {
  margin: 0px;
  padding: 0px;
}

.mainwrapper {
  width: 1024px;
  margin: 0 auto;
}

.pagebanner {
  height: 250px;
  margin: 0;
}

.pagebanner img {
  width: 100%;
  height: 100%;
}

.main {
  margin: 0;
}

.navbar {
  background-color: brown;
  min-height: 500px;
  width: 20%;
  float: left;
}

.navbar li {
  list-style: none;
  margin-bottom: 15px;
}

.navbar a {
  color: #fff;
  font-size: 20px;
}

.headersd {
  width: 80%;
  float: left;
  padding: 0;
  min-height: 500px;
}

.header {
  background-color: #000;
  text-align: center;
}

.header h1 {
  color: #fff;
  margin: 0;
}

.subheading {
  background-color: #f8d631;
  text-align: center;
}

.subheading h2 {
  background-color: #f8d631;
  margin: 0;
}

.table {
  align: center;
  padding-left: 50px border: 20px;
}

.footer {
  background-color: darkgreen;
  height: 20px;
  margin-bottom: 0px;
}
<div class="mainwrapper">
  <div class="pagebanner">
    <img src="https://cdn-images-1.medium.com/max/1400/1*278tqw9zNPe2WCAz29Wzdw.jpeg" alt="PageBanner">
  </div>
  <!--PageBanner-->

  <div class="main">
    <div class="navbar">
      <ul>
        <li>
          <a href="#">Information</a>
        </li>
        <li>
          <a href="#">Home</a>
        </li>
      </ul>
    </div>
    <!--Navbar-->

    <div class="headers">
      <div class="header">
        <h1>The Club Site</h1>
      </div>
      <!--Main page heading section-->

      <div class="subheading">
        <h2>Members Prices</h2>
      </div>
      <!--Sub heading section-->
    </div>

  </div>
  <div class="content">
    <div class="table">
      <table>
        <th>Discount Prices</th>
        <tr>
          <td><img src="https://imgur.com/S1JVX6K" </td>
            <td><img src="https://imgur.com/uzkB81W" </td>
              <td><img src="https://imgur.com/YvnOW4s" </td></tr>
        <tr>
          <td><img src="https://imgur.com/f2wnDXT" </td>
            <td><img src="https://imgur.com/XiBYnS2" </td>
              <td><img src="https://imgur.com/mGcCorr" </td></tr>
      </table>
    </div>
    <!--Table Section-->

  </div>
  <!--Content section-->

  <div class="footer">
    <footer>wsrgferg</footer>
  </div>
  <!--Footer section-->
</div>
<!--Endwrapper-->

Answer №1

Incorporate margin:0 auto into the table element, update th to h3, and set h3 alignment to text-align:center.

<head>
    <meta charset="utf-8" />
    <title>Bazaar Ceramics</title;

<style>

body {
    margin: 0px;
    padding: 0px;
}

.mainwrapper {
    width: 1024px;
    margin: 0 auto;
}

.pagebanner {
    height: 250px;
    margin: 0;
}

.pagebanner img {
    width: 100%;
    height: 100%;
}

.main {
    margin: 0;
}

.navbar {
    background-color: brown;
    min-height: 500px;
    width: 20%;
    float: left;
}

.navbar li {
    list-style: none;
    margin-bottom: 15px;
}

.navbar a {
    color: #fff;
    font-size: 20px;
}

.headersd {
    width: 80%;
    float: left;
    padding: 0;
    min-height: 500px;
}

.header {
    background-color: #000;
    text-align: center;
}

.header h1 {
    color: #fff;
    margin: 0;
}

.subheading {
    background-color: #f8d631;
    text-align: center;
}

.subheading h2 {
    background-color: #f8d631;
    margin: 0;
}

.table {
    align: center;
    padding-left:50px
    border: 20px;
    }
.footer {
    background-color: darkgreen;
    height:20px;
    margin-bottom:0px;
}   
</style>

</head>

<body>

    <div class="mainwrapper">
        <div class="pagebanner">
          <img src="https://cdn-images-1.medium.com/max/1400/1*278tqw9zNPe2WCAz29Wzdw.jpeg" alt="PageBanner">
        </div><!--PageBanner-->

    <div class="main">
        <div class="navbar">
            <ul>
                <li>
                    <a href="#">Information</a>
                </li>
                <li>
                    <a href="#">Home</a>
                </li>
            </ul>
        </div><!--Navbar-->

    <div class="headers">
    <div class="header">
            <h1>The Club Site</h1>
    </div><!--Main page heading section-->

    <div class="subheading">
            <h2>Members Prices</h2>
    </div><!--Sub heading section-->
    </div>

    </div>
    <div class="content">
        <div class="table"> 
            <table style="margin:0 auto;" >
            <h3 style="text-align:center;">Discount Prices</h3>
            <tr><td><img src="HTML Pract A/images/smaller/bcpot002_smaller.jpg"</td><td><img src="HTML Pract A/images/smaller/bcpot006_smaller.jpg"</td><td><img src="HTML Pract A/images/smaller/bcpot013_smaller.jpg"</td></tr>
            <tr><td><img src="HTML Pract A/images/smaller/bcpot002_smaller.jpg"</td><td><img src="HTML Pract A/images/smaller/bcpot006_smaller.jpg"</td><td><img src="HTML Pract A/images/smaller/bcpot013_smaller.jpg"</td></tr>
            </table>
        </div><!--Table Section-->  

    </div><!--Content section-->

    <div class="footer">
        <footer>wsrgferg</footer>
    </div><!--Footer section-->
    </div><!--Endwrapper-->

</body>



</html>

Answer №2

body {
  margin: 0px;
  padding: 0px;
}

.mainwrapper {
  width: 1024px;
  margin: 0 auto;
}

.pagebanner {
  height: 250px;
  margin: 0;
}

.pagebanner img {
  width: 100%;
  height: 100%;
}

.main {
  margin: 0;
}

.navbar {
  background-color: brown;
  min-height: 500px;
  width: 20%;
  float: left;
}

.navbar li {
  list-style: none;
  margin-bottom: 15px;
}

.navbar a {
  color: #fff;
  font-size: 20px;
}

.headersd {
  width: 80%;
  float: left;
  padding: 0;
  min-height: 500px;
}

.header {
  background-color: #000;
  text-align: center;
}

.header h1 {
  color: #fff;
  margin: 0;
}

.subheading {
  background-color: #f8d631;
  text-align: center;
}

.subheading h2 {
  background-color: #f8d631;
  margin: 0;
}

.table {
  align: center;
  padding-left: 50px border: 20px;
}

.footer {
  background-color: darkgreen;
  height: 20px;
  margin-bottom: 0px;
}

.content {
  min-height: 400px;
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title>Bazaar Ceramics</title>
</head>

<body>

  <div class="mainwrapper">
    <div class="pagebanner">
      <img src="https://cdn-images-1.medium.com/max/1400/1*278tqw9zNPe2WCAz29Wzdw.jpeg" alt="PageBanner">
    </div>
    <!--PageBanner-->

    <div class="main">
      <div class="navbar">
        <ul>
          <li>
            <a href="#">Information</a>
          </li>
          <li>
            <a href="#">Home</a>
          </li>
        </ul>
      </div>
      <!--Navbar-->

      <div class="headers">
        <div class="header">
          <h1>The Club Site</h1>
        </div>
        <!--Main page heading section-->

        <div class="subheading">
          <h2>Members Prices</h2>
        </div>
        <!--Sub heading section-->
      </div>

    </div>
    <div class="content">
      <div class="table">
        <table style="margin:0 auto;">
          <h3 style="text-align:center;">Discount Prices</h3>
          <tr>
            <td><img src="HTML Pract A/images/smaller/bcpot002_smaller.jpg" </td>
              <td><img src="HTML Pract A/images/smaller/bcpot006_smaller.jpg" </td>
                <td><img src="HTML Pract A/images/smaller/bcpot013_smaller.jpg" </td></tr>
          <tr>
            <td><img src="HTML Pract A/images/smaller/bcpot002_smaller.jpg" </td>
              <td><img src="HTML Pract A/images/smaller/bcpot006_smaller.jpg" </td>
                <td><img src="HTML Pract A/images/smaller/bcpot013_smaller.jpg" </td></tr>
        </table>
      </div>
      <!--Table Section-->

    </div>
    <!--Content section-->

    <div class="footer">
      <footer>This is the Footer</footer>
    </div>
    <!--Footer section-->
  </div>
  <!--Endwrapper-->

</body>



</html>

If you set a fixed height for your .content, it will always take up that space and your footer will be positioned directly below it.

The issue with this approach is that if your content only occupies a small portion of the screen, your footer will appear right after it, creating a large empty space below. As more content is added, the footer will move down as needed to accommodate the additional content.

While this method may not be the most responsive, it provides a working solution. Suggestions for better responsiveness are welcome!

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

The process of creating a functional search bar in Django

I created a search bar, but I am facing an issue where no titles appear until I start typing. Once I type in one title, all the titles suddenly appear. How can I fix this problem? index.html def index(request): query = request.GET.get('srh' ...

A guide on utilizing Xpath to reference a tag within a class

Trying to obtain the website link by using xpath and selenium with a reference to the class pv-contact-info__contact-type ci-websites. [Here is the html snippet being referenced][1] sel = Selector(text=driver.page_source) website = sel.xpath("//*[@class= ...

Unlock the Potential of Spring REST-JWT-JavaScript for Seamless Transitions

In my Java Spring REST back-end, I am implementing a security feature using Json Web Tokens instead of sessions. For the front-end, I plan to use JavaScript and jQuery for sending requests to the back-end, along with HTML. After a successful login, I stor ...

Connect the CSS file in React index.html to the Flask backend

I am attempting to connect a CSS template that is serving static backend content through Flask with my React frontend. Here is the structure I am working with: client/ src/ components/ menu.jsx public/ ...

Enhancing the Syntax of If and If Else in Jquery Functions

I'm struggling to simplify and optimize this block of code. Would appreciate any help in making it more efficient! var status = "closed"; $(document).on('click', '[data-toggle-nav]', function(event) { if ($(this) && status = ...

What is causing the columns in Foundation 6 to not align next to each other?

At 1090px screen width or in tablet mode, the columns do not align side by side and instead one is pushed down creating a white space between them. I am using Foundation 6 with 12 columns, but it does not work well on medium-sized screens; it only function ...

Iterating through elements within a Div will retrieve the initial element exclusively

Is there a way to loop through all elements within the MainDiv Div in order to retrieve their values? Currently, I am only able to retrieve the value of the first element. <div id="MainDiv"> <input type="text" id="MyText"value="Text1" /> ...

What is the preferred approach in JavaScript: having a single large file or multiple smaller files?

Having a multitude of JavaScript files loaded on a single page can result in decreased performance. My inquiry is this: Is it preferable to have individual files or combine them into one JavaScript file? If consolidating all scripts into one file is the ...

Retrieve the information from a website and display it on the current webpage using an ajax request

Is there a way to insert parsed HTML content into my webpage using just a link from another page? I'm attempting to use an AJAX call, but I keep receiving an error. Below is the code I've written, and the browser doesn't seem to be the issue ...

Angular - developing a custom web element to enhance the project

Is there a way to convert a single module into a web component and integrate it within the same project? Specifically, I have 3 modules in my project and I am looking to transform only module1 into a web component and incorporate it seamlessly. Thank you! ...

Is your PHP random advertisement feature malfunctioning?

<div id="bannerAd"> <?php //THIS SCRIPT RANDOMLY SELECTS AN AD. $randomAd = rand(1,3); switch($randomAd) { case "1": $adLink = "/sale.php"; $imageFile = "/images/saleAd.png"; ...

Adjust the bootstrap switch component to be in the 'checked' state when the mode is set to Dark

I have stored a theme for my web application in the localStorage and I want to dynamically add the checked value to the Switch component if the mode is set to 'dark', or unchecked if the mode is 'light'. However, whenever I set the them ...

Other options to consider besides using flex wrapping

Is it possible to use other methods to wrap these image items with the display: flex; property besides using the flex-wrap property? Are there alternative approaches available? body { margin: 0px; } img {} h1 {} p {} a { background-color: #ddd; ...

Customize style with Dart programming language

Is it possible to modify a HTML element's CSS with DART? I've searched around but couldn't find clear instructions on how to accomplish this or if it's feasible at all. The main objective is to alter the position of a button on a webp ...

On three out of five pages, Mozilla Firefox and Internet Explorer are causing extra spacing in my navigation section, yet not on every page

I've been troubleshooting my website and can't seem to pinpoint the issue. I have 5 pages all connected to the same CSS file and created in a consistent manner. Interestingly, Safari, Chrome, and Opera display everything correctly. However, in Fi ...

How can we use jQuery to change the format of a

I'm working on a project where I want the calendar to display the date that the user picks. Right now, my "{{date}}" is in the format 2016-01-11, but it keeps showing one day before the selected date. I would like it to display as mm/dd/yyyy. I belie ...

The Google Visualization chart fails to display properly once CSS is applied

Struggling with a graph display issue here. It's quite perplexing as it works fine on older laptops and Safari, but not on Chrome or older versions of Firefox. Works like a charm on my old laptop and Safari, but fails on Chrome and Firefox (haven&apo ...

Guide on applying css to a single element while concealing another using Jquery

Looking to enhance my javascript skills by adding CSS to another element when a particular element is hidden. I've got the hiding/showing part down, but now I want to take it a step further. For example: How can I style div2 differently when div1 is ...

Master the art of manipulating tags in Django templates using JavaScript

In my Django quiz app, there are two main components. The first part involves displaying 10 sentences with corresponding audio to help with memorization, one per page. The second part consists of asking questions based on the same set of sentences. I initi ...

Strange behavior in Internet Explorer when using jQuery to simulate a click on an input=file element

My customized jQuery and HTML code achieves the following purpose: There is a placeholder image that can be clicked by the user, triggering a file selection dialog to open. Once a file is chosen, the corresponding multipart form is sent to the server. To ...