How can I style my tables to have different border spacing between the table head and table body?

When it comes to tables, I want to customize the column spacing in a specific way. I need space between columns in the table header but no gaps between columns in the table body.

How can I achieve this by including border space only in the thead section?

Check out the code snippet below that I've been working on:

View Code on jsfiddle

table.OrderDetail {
    font-family: Arial;
    border-collapse: collapse;
}
.OrderDetail tbody {
    padding: 10px;
    text-align: left;
    font-size:13px;
    font-family: Arial;
}
.OrderDetail thead {
    padding: 7px;
    text-align: left;
    background-color: #E0E0E0;
    color:#989898;
    font-size:10px;
}
.OrderNumber {
    font-family: Helvetica, Arial, sans-serif;
    background-color: #99CCFF;
    text-align: left;
}
.OrderNumber thead {
    font-size:10px;
}
.OrderNumber tbody {
    font-size:15px;
}
tr.separating_line td {
    border-bottom: 1px solid gray; /* set border style for separated rows */
}
.OrderDetail td {
    padding: 10px 0; /* 10px top & bottom padding, 0px left & right */
}
.OrderDetail th {
    padding: 5px 0; /* 10px top & bottom padding, 0px left & right */
}
<table class="OrderNumber" style="width:100%">
    <thead>
        <tr></tr>
        <tr>
            <td>Order Number</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>234456667</td>
        </tr>
        <tr></tr>
    </tbody>
</table>
<br></br>
<table class="OrderDetail" style="width:100%">
    <thead>
        <tr>
            <th>Line Item Number</th>
            <th>Item Description</th>
            <th>Ship To Location</th>
            <th>Carrier</th>
            <th>Tracking Number</th>
        </tr>
    </thead>
    <tbody>
        <tr class="separating_line">
            <td>1</td>
            <td>$itemDescription</td>
            <td>$shipToLocation</td>
            <td>$carrier</td>
            <td style="color:#33CCFF">$trackingNumber</td>
        </tr>
        <tr class="separating_line">
            <td>1</td>
            <td>$itemDescription</td>
            <td>$shipToLocation</td>
            <td>$carrier</td>
            <td style="color:#33CCFF">$trackingNumber</td>
        </tr>
    </tbody>
</table>

I have applied 'border-collapse: collapse' to the table, which makes all borders continuous. But now, I'm looking for a way to keep the borders continuous at the body level and separate them at the head level of the table. Is this even possible?

Answer №1

Looking to enhance the appearance of your table headers? Try adjusting the border width for the th cells. This can create a clear separation between headings, which seems to be what you're looking for.

.OrderDetail th {
    padding: 5px 0; /* 10px top & bottom padding, 0px left & right */
    border-right: 5px solid white;
}
.OrderDetail th:last-child {
    border-right: 0;
}

Explore this example on jsfiddle

Answer №2

If you're searching for a specific solution, consider focusing on the individual cells themselves.

.ProductDetail thead th { padding: 7px; }
.ProductDetail tbody td { padding: 3px; }

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

What steps can I take to guarantee that a select change event occurs following the setting of ngmodel in Angular2?

I am facing an issue with a select element wherein a basic (change) handler is attached along with an ngmodel. Whenever an <option> with a ng value is set, the change handler triggers before the [(ngModel)] reflects the new values. <div> ...

Issue with Bootstrap landing page layout - Container not adjusting to screen size correctly

Currently, I am engaging in a project to develop a landing page using Bootstrap as part of my practice. Unfortunately, I encountered an issue with the layout as the container does not align properly with the screen size. This imbalance causes the screen or ...

Is it possible to target elements based on a specific CSS3 property they use?

Is there a method to target all elements in the DOM with a border-radius other than 0? If anyone has suggestions, it would be greatly appreciated! ...

What is causing the div element to act as a container?

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95f7fafae1e6e1e7f4e5d5a1bba3bba5">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-B0v ...

Is it possible to utilize onclick for various table cells in jQuery?

I have a situation where I need to loop through dates and display table content accordingly. Could someone please assist me in figuring out how to do this? index.html.erb <% @batches.each do |batch| %> <tr> **<td class = "pie" id ...

Add the following code snippet below every second set of two paragraphs that are enclosed within h

I am looking to add Advertisements following the 2nd paragraph in every h2 tag. Here is an example of what I want: <h2>Sub title</h2> <p>1st paragraph</p> <p>2nd paragraph</p> <div>INSERTED AD</div> functio ...

Chrome is experiencing a rendering problem as a result of using @Font-Face

Having trouble with rendering in my Angular 4 application, similar to the issue outlined in this post about Angular 2 Chrome DOM rendering problems. Despite there being a solution provided in that post, I am still facing difficulties when navigating betwee ...

Tips for keeping your button fixed in place

I am encountering an issue where my button moves below the select dropdown list when I try to make a selection. Is there a way to keep the button in place even when the dropdown list from the select box is visible? For reference, here is the current outp ...

Tips on avoiding blurring when making an autocomplete selection

I am currently working on a project to develop an asset tracker that showcases assets in a table format. One of the features I am implementing is the ability for users to check out assets and have an input field populated with the name of the person author ...

Display various items using only one EJS scriptlet tag

I'm currently facing a challenge with rendering two objects using EJS. I am curious to know if it is feasible to render them both within the same pair of scriptlet tags or if they need to be rendered separately? So far, I have been able to successful ...

Can you guide me on where to find the login with Facebook button on this site?

I am currently working on integrating a Facebook authentication system into my app, but I find the default log in button provided by Facebook developers section to be quite unappealing. My Question: I am curious about how websites like Stack Overflow man ...

step-by-step guide on transferring the text content of an HTML paragraph element to another HTML paragraph element through JavaScript in ASP.NET

I'm looking for help with passing the text value from one HTML paragraph element to another when a JavaScript function is called. The function loads a div element with an enlarged image and a paragraph content. Below is the code I am using: JavaScrip ...

What methods does the W3C CSS Validator use to recognize a CSS3 document?

Help Needed! Can someone tell me how to specify a CSS3 file for validation by the W3C? In HTML5, we use <!DOCTYPE html>, but what should we use in a CSS file? Whenever I try to validate my CSS file containing CSS3 elements like @font-face and box- ...

Troubleshooting: Image Not Displaying in Twitter Bootstrap Theme

I'm new to using bootstrap and I'm encountering an issue where my image is not showing up. Strangely, the default background image is appearing even though I have not referenced it in the HTML or CSS files. View my code here ...

Create a line with elements that end on the next line without taking up the full width

In a row of three links, I want the third one to be on the next line, but using .new-line { display:block; } makes the link 100% width on the next line, causing the entire area to be clickable. I also have content in the :before that should appear inline w ...

Creating CSS style rules for aligning table column headers in JavaFXML

Is it possible to style columns individually in a tableview? I have been attempting to make some column headers left-aligned and others right-aligned, as shown below: | hdr1 | hdr2 | hdr3 | hdr4 | In my css stylesheet, I experimented with the following ...

JavaScript: Creating Custom IDs for Element Generation

I've been developing a jeopardy-style web application and I have a feature where users can create multiple teams with custom names. HTML <!--Score Boards--> <div id="teamBoards"> <div id="teams"> ...

Arrange the select default option using AngularJS as the first option

I've been working on a project using Angular where I fetch data from a JSON file and push it to an array object. This data is then displayed in the options of a select element. My issue is: The default option with selection appears first, but I only ...

The login form is not being recognized by Chrome

I've been working on creating a login form for my website. Oddly enough, when I try to use it on Chrome, it doesn't prompt me to save my password. Yet, it functions properly on other browsers like Edge, Firefox, and Internet Explorer. Here' ...

"Troubleshooting: Why is my Bootstrap modal window only printing a

I've encountered an issue with printing the content of a Bootstrap modal window. Previously, the code I had was working fine but now it seems to be malfunctioning. Content is dynamically added to the form using appendChild() in a separate function. Ho ...