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

Grouping and retrieving values from an array of JavaScript objects

I am looking to implement a groupBy function on the object array below based on the deptId. I want to then render this data on a web page using AngularJS as shown: Sample Object Array: var arr = [ {deptId: '12345', deptName: 'Marketin ...

Struggling with textpath SVG elements in jQuery

Currently, I am implementing SVG in my project and aiming to apply the toggleClass function using jQuery on the textpath elements upon clicking. My initial plan was: $("text#names > textpath").click(function() { $(this).toggleClass("newClass"); }) ...

How to properly set margins for button components in Material UI

I'm working with a centered Toolbar in Material UI that consists of 3 components, each being a button. My goal is to add some margin around each button. I attempted to use the {mt} option within the component button, but didn't see any changes re ...

Change the z-index of divs when clicked

When a button is clicked, I want to iterate through a group of absolutely positioned children divs with varying z-indexes. The goal is for the z-index of the currently visible div to decrease on each click, creating a looping effect where only one div is v ...

Preserving the initial input values in a secure manner for future reference, utilizing either an object or a

Recently, I've started revisiting a script I created a while back that checks for changes in a form to prompt a message asking 'Would you like to save your changes?'... One thing that's been on my mind is whether I should store the ori ...

Is it possible to prevent the text from appearing in the text box when a button is

I have successfully implemented a feature where clicking on the button (click on me) in HTML displays a textbox along with another button (show) on the screen. The text written in the textbox is visible when the show button is clicked. However, after the i ...

Using a custom font in a Django project without relying on the Google Fonts API

I've hit a roadblock in my programming journey and I'm seeking help. As a newcomer to both programming and Django, I've been following a helpful tutorial up until part 4. Everything was going well until I stumbled upon a new font online cal ...

HTML 5 Video VTT File: A must-have for optimal video playback

Having trouble getting the subtitle.vtt file to load on Chrome with this code. Can anyone offer any insights? <div id="videoKilledTheRadioStar"> <video id="Tutorial" width="420" autoplay controls> <source src="videos/shaco.mp4" type="vi ...

Display the website logo when users share on WhatsApp

My goal is to have my website icon appear in WhatsApp when I share it (similar to the example below). https://i.stack.imgur.com/KCWi8.jpg I initially tried using this code, but it didn't work: <link rel="shortcut icon" href="css/img/favicon/favi ...

Troubleshooting: Why is Angular2 ngClass malfunctioning?

I am having trouble adding a class based on a condition <tr *ngFor="let time of times; let i = index"> <td [ngClass]="{'red-time':checkInvalid(time['Proles Arrive'])}">{{time['Proles Arrive']}}</td& ...

Shifting an image within a div using HTML5 and CSS3

I am wondering how to position the image 50px from the top and 50px from the left within the div. Should I use padding for this? <header> <img src="logo.png" alt="" /> </header> header { width... height: background: (url) } ...

What is the best way to incorporate background colors into menu items?

<div class="container"> <div class="row"> <div class="col-lg-3 col-md-3 col-sm-12 fl logo"> <a href="#"><img src="images/main-logo.png" alt="logo" /> </a> ...

Bulma: Tips for creating equally sized buttons?

I am working with Bulma CSS and trying to ensure that all my buttons are the same size. Currently, each button appears to have a different size based on the text content. I have looked into using the "is-fullwidth" option, but it makes the buttons too la ...

Tips for preventing a div from overflowing in col-md-12 in Bootstrap 3

Is there a way to maintain the same width for the image and div below? Everything looks good until the window size is between 545px to 575px. The .header width changes only at col-md-12. How can I preserve the aspect ratio? VIEW SCREENSHOT CODEPEN LINK ...

Maintain the div's aspect ratio by adjusting its width according to its height

I am seeking a way to maintain the width of the .center div in relation to its height, following a 4:3 aspect ratio (4 units wide for every 3 units high). The height of the div should be set to 100%, and I also need to align the div horizontally at the cen ...

Is it possible for an SVG to derive its dimensions from the containing element?

I am currently in the process of transitioning a Vue/Vuetify application from using web fonts for Material Design Icons to utilizing SVG icons instead. With the web font, an example of a heading that includes an icon looks like this: <template> &l ...

Emphasize the interactions within the table cells based on their corresponding column and row

I'm looking to achieve a specific interaction in my Angular Material table. I want to highlight the table cell interactions with column and row by extending the highlighting up to the column header and left to the row header. Is this something that ca ...

Using Bootstrap 3 to create a carousel with a seamless fading transition as the background

I want to utilize Bootstrap Carousel as the background for my website. I've successfully incorporated a standard carousel as the background, but I'm encountering difficulties with making fade transitions. Here is my current implementation: HTML: ...

Step-by-step guide on utilizing jQuery to fade out all elements except the one that is selected

There are multiple li elements created in this way: echo '<ul>'; foreach ($test as $value){ echo '<li class="li_class">.$value['name'].</li>'; } echo '</ul>'; This code will generate the fol ...

What are some effective strategies for avoiding empty fields showing on an email form?

My HTML form is linked to a PHP Email handler, and it's working well except for one issue. When the email is delivered, it includes all fields, even the empty ones. I want it to only display filled-in fields. I tried using an IF statement that checks ...