How about this: "Is the text in the columns of the <table> body aligned to the

In my HTML5 table, I have 3 header columns with a colspan of 2 each, making it a total of 6 columns wide. Below each header are 2 body columns corresponding to that header. While the individual columns are aligned left, I am now looking to center align the entire body so it lines up with the headers. Despite trying the margin: 0 auto trick with a defined width, it doesn't seem to be working as expected.

Here is how it appears currently:

This is my HTML:

<div id="areas">
    <table>
        <thead>
            <tr>
                <td colspan="2">Delaware County</td>
                <td colspan="2">Main Line</td>
                <td colspan="2">Chester County</td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td class="city">Broomall</td>
                <td class="zip">19008</td>
                <td class="city">Ardmore</td>
                <td class="zip">19003</td>
                <td class="city">Paoli</td>
                <td class="zip">19301</td>
            </tr>
            <tr>
                <td class="city">Chester</td>
                <td class="zip">19013</td>
                <td class="city">Bala Cynwyd</td>
                <td class="zip">19004</td>
                <td class="city">Avondale</td>
                <td class="zip">19311</td>
            </tr>
            <tr>
                <td class="city">Aston</td>
                <td class="zip">19014</td>
                <td class="city">Bryn Mawr</td>
                <td class="zip">19010</td>
                <td class="city">Berwyn</td>
                <td class="zip">19312</td>
            </tr>
         </tbody>
      </table>
</div>

And here is my CSS:

#areas {
    position: relative;
    margin: 30px auto 60px auto;
    width: 950px;
    padding: 20px;
    background-color: #4B004B;
    -webkit-box-shadow: 11px 11px 15px rgba(50, 50, 50, 0.85);
    -moz-box-shadow:    11px 11px 15px rgba(50, 50, 50, 0.85);
    box-shadow:         11px 11px 15px rgba(50, 50, 50, 0.85);
    border: 3px outset gold;
}

#areas thead td {
    font-family: 'electricalregular';
    -webkit-text-stroke: 1px orange;
    letter-spacing: 2px;
    font-size: 10pt;
    font-weight: 100;
    text-align: center;
    width: 316px;
    color: gold;
    padding: 0 0 15px 0;
}

#areas tbody {
    width: 950px;
    margin: 0 auto;
}

#areas tbody td {
    font-family: 'CommunistSans';
    color: gold;
    font-weight: 100;
    padding: 0 0 5px 0px;
    width: 158px;
}

#areas .zip {
    text-align: left;
}

#areas .city {
    text-align: left;
}

Answer №1

One potential solution is to experiment with:

#areas .zip, #areas .city { position: relative; left: 30px; }

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 issue of the horizontal navigation bar not functioning properly persists when a specific width

I am currently working on building a horizontal navigation bar using CSS. What puzzles me is that when I specify a width for my ol tag, the horizontal float function does not seem to cooperate. However, if I remove the width property, everything works jus ...

Tips for creating an Instagram photo collection on your own blog

Currently, I am on a quest to discover and either personalize or construct my very own Instagram photo gallery for the purposes of my personal blog website. The ownership of the website is fully mine which implies that I have the liberty to write PHP code ...

Placing content within documents

Whenever the "Comment" button is clicked, the new file $cname.txt does not open, preventing the user from entering values into the file and as a result, nothing gets posted. How can I ensure that both cname and comment are successfully posted when the us ...

Issues arising from utilizing Twitter Bootstrap 3.1.x, the box-sizing property, and Revolution Slider

I'm currently working on a PyroCMS theme that is built with Twitter Bootstrap 3.1.x and includes Revolution Slider. However, I've encountered an issue where the property box-sizing: border-box; creates an unwanted grey border as shown in the imag ...

Display a message in jQuery when the same option is chosen more than once

I need help with my form that has an input text field and a select dropdown. Here is the markup: <div id="form-wrap" style="width:500px; margin: 0 auto;"> <table> <tr> <th width="55%">Service Name</th> ...

Retrieve JSON data by making a POST request to a website's API

Can you help me retrieve Json data from a website API using JavaScript? I'm trying to fetch quotes from the following website: for my quotes generator page. While I have some understanding of making GET requests, it seems that this API requires POST ...

Width column responsive tab

I have a large bootstrap table with multiple columns that require specific widths. I want to ensure all columns are displayed with a horizontal scroll bar if needed. Despite looking at examples, I am facing some graphical issues. My approach involves usin ...

Instructions on creating an input field and a slider simultaneously

Currently, I am exploring the world of CSS 3D transforms and I am particularly interested in creating sliders to manage these transforms. I recently stumbled upon the Three.js editor and was impressed by how it handles the positioning, rotation, and scalin ...

Tips for toggling the radio button value to either checked or unchecked state

<input type="radio" name="imgsel" value="" checked /> I am looking to have a radio button that is initially checked with a value of 'present'. When the button is unchecked, I want the value to change to &apos ...

Positioning a full-width background-image in the center is causing the page to expand

I've been struggling to find a solution to this issue for hours, scouring the internet with no success. The problem I'm facing is trying to center a background image on the page. However, when using the method shown here, it ends up stretching t ...

Include an HTML attribute within a given string

Using jQuery, I am adding HTML content to a div. The variables rowString and inputString have been defined beforehand: $("#filterContainer").append( rowString + `<label class='filterLabel' for=${filter}>${filter}< ...

Eclipse-generated JAR files are failing to execute in Java. What could be causing this problem?

All of my jars are running fine except for one. The source files compile and work correctly, and I am using a JFrame for the GUI display. In the wizard, I have only selected "export java source files and resources". However, when I try exporting with bot ...

What is causing my click event, which I included in a table row, to not function properly?

I'm having trouble with this code I wrote. When I click on a row in the table (tr tag), nothing happens and I can't figure out why... readDetails(){ this.router.navigate(['/dettaglio-contributivo']); console.log("It should work ...

I am encountering an issue where my Vue navbar is successfully changing the route but not updating the corresponding router-view

I have been working on a single-page application using Vue and I encountered an issue with the navbar when navigating through routes. The problem is that after the first click on a navbar item, the route changes successfully but the router-view does not up ...

What is the best way to design three flexible divs using display: table without the use of JavaScript?

https://i.sstatic.net/bEC4Y.png Is it possible to create a responsive layout with three divs that behave in the following way: When the viewport is narrow, the three divs stack on top of each other When the viewport is average, the first div spans full ...

Issues with CSS transparent color overlay fading on iOS device (Note: Since the original

I have created a grid of images with a unique effect where a semi-transparent overlay appears when you hover over them, revealing some text. I wanted to achieve the same effect on mobile devices by making the overlay fade in when tapped instead of hovered ...

Customizing the step function of HTML5 input number with jQuery: A guide

Is there a way to modify the step value in HTML5 number inputs for my web application? I would like it to increment and decrement by 100 instead of 1. I attempted the following approach: $("#mynumberinput").keydown(function(e){ if (e.keyCode == 38) / ...

Adjust mouse coordinates to be relative to the coordinates of the <canvas> element

I'm currently facing the challenge of determining the exact location of the mouse on a canvas grid while still maintaining resizability. As of now, I have the mouse coordinates based on its position on the screen (x and y). The issue arises from the ...

Create animated changes in height for a mdDialog as elements are shown or hidden

Utilizing Angular Material, I have implemented tabs within an md-dialog. The dialog smoothly adjusts its height based on the content of the active tab during navigation. However, when utilizing an ng-if directive to toggle visibility of content, there is n ...

Is there a timeline for when Opera will begin supporting the border-radius property

Any updates on the release date for border-radius support? I remember hearing about -o-border-radius in the past, what's the status on that now? ...