issue arising where the table's border is not displaying

I'm confused about why the border of the first tbody tr's td is not visible.

https://i.stack.imgur.com/Fwlv7.png I can't see any reason why the border is not showing up.

Here's what I've figured out:

  1. If the natural height of th is greater than the fixed height for th, the first tbody tr's td will be visible.
  2. If there is no code th{height: xxpx;}, the first tbody tr's td will be visible.

.table {
  border-spacing: 0;
  border-collapse: collapse;
}

.table.summary-style
{
    font-size: 11px;

    width: 100%;

    table-layout: fixed;

    text-align: center;

    color: #666;
    border-bottom: 1px solid #666;
    background: #fff;
}

.table.summary-style caption
{
    font-size: 0;
    line-height: 0;

    display: none;
    overflow: hidden;
    clip: rect(1px 1px 1px 1px);
    /* IE6, IE7 */
    clip: rect(1px, 1px, 1px, 1px);

    width: 0;
    height: 0;
    margin: 0;
    padding: 0;

    opacity: 0;
}

.table.summary-style thead th
{
    font-size: 16px;
    line-height: 1;

    position: relative;

    box-sizing: border-box;
    height: 38px;
    padding: 5px 4px;

    text-align: center;
    vertical-align: middle;

    color: #666;
    background: #ddd;
}

.table.summary-style > tbody > tr > td
{
    font-size: 13px;
    line-height: 1.38;

    box-sizing: border-box;
    height: 36px;
    padding: 4px 10px;

    text-align: left;
    vertical-align: middle;

    color: #666;
    border-top: 1px solid #666;
    background: #fff;
}
<table class="table summary-style">
         
         
        <thead>
            <tr>
                <th scope="col">title</th>
                <th scope="col">title</th>
                <th scope="col">title</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td colspan="3">No Data.</td>
            </tr>
            <tr>
                <td>content</td>
                <td>content</td>
                <td>content</td>
            </tr>
            <tr>
                <td>content</td>
                <td>content</td>
                <td>content</td>
            </tr>
            <tr>
                <td>content</td>
                <td>content</td>
                <td>content</td>
            </tr>
        </tbody>
    </table>

Answer №1

The reason for this issue is that setting position: relative; on the .table.summary-style thead th elements causes them to appear above the borders of other elements. This occurs even when box-sizing: border-box; is applied, as the borders of table elements are collapsed together. To resolve this, you can either remove position: relative; from the first row or eliminate border-collapse: collapse; from the .table styling.

.table {
  border-spacing: 0;
  border-collapse: collapse;
}

.table.summary-style
{
    font-size: 11px;

    width: 100%;

    table-layout: fixed;

    text-align: center;

    color: #666;
    border-bottom: 1px solid #666;
    background: #fff;
}

.table.summary-style caption
{
    font-size: 0;
    line-height: 0;

    display: none;
    overflow: hidden;
    clip: rect(1px 1px 1px 1px);
    /* IE6, IE7 */
    clip: rect(1px, 1px, 1px, 1px);

    width: 0;
    height: 0;
    margin: 0;
    padding: 0;

    opacity: 0;
}

.table.summary-style thead th
{
    font-size: 16px;
    line-height: 1;

    box-sizing: border-box;
    height: 38px;
    padding: 5px 4px;

    text-align: center;
    vertical-align: middle;

    color: #666;
    background: #ddd;
}

.table.summary-style > tbody > tr > td
{
    font-size: 13px;
    line-height: 1.38;

    box-sizing: border-box;
    height: 36px;
    padding: 4px 10px;

    text-align: left;
    vertical-align: middle;

    color: #666;
    border-top: 1px solid #666;
    background: #fff;
}
<table class="table summary-style">
         
         
        <thead>
            <tr>
                <th scope="col">title</th>
                <th scope="col">title</th>
                <th scope="col">title</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td colspan="3">No Data.</td>
            </tr>
            <tr>
                <td>content</td>
                <td>content</td>
                <td>content</td>
            </tr>
            <tr>
                <td>content</td>
                <td>content</td>
                <td>content</td>
            </tr>
            <tr>
                <td>content</td>
                <td>content</td>
                <td>content</td>
            </tr>
        </tbody>
    </table>

Answer №2

Consider this code snippet for your table styling:

table,
td,
th {
  border-collapse: collapse;
  padding: 0.5em 1em;
  border: 2px solid black;
}

.table.summary-style {
  font-size: 11px;
  width: 100%;
  table-layout: fixed;
  text-align: center;
  color: #666;
  border-bottom: 1px solid #666;
  background: #fff;
}

.table.summary-style caption {
  font-size: 0;
  line-height: 0;
  display: none;
  overflow: hidden;
  clip: rect(1px 1px 1px 1px);
  /* IE6, IE7 */
  clip: rect(1px, 1px, 1px, 1px);
  width: 0;
  height: 0;
  margin: 0;
  padding: 0;
  opacity: 0;
}

.table.summary-style thead th {
  font-size: 16px;
  line-height: 1;
  position: relative;
  box-sizing: border-box;
  height: 38px;
  padding: 5px 4px;
  text-align: center;
  vertical-align: middle;
  color: #666;
  background: #ddd;
}

.table.summary-style>tbody>tr>td {
  font-size: 13px;
  line-height: 1.38;
  box-sizing: border-box;
  height: 36px;
  padding: 4px 10px;
  text-align: left;
  vertical-align: middle;
  color: #666;
  border-top: 1px solid #666;
  background: #fff;
}
<table class="table summary-style">
        <thead>
            <tr>
                <th scope="col">Title</th>
                <th scope="col">Title</th>
                <th scope="col">Title</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td colspan="3">No Data.</td>
            </tr>
            <tr>
                <td>Content</td>
                <td>Content</td>
                <td>Content</td>
            </tr>
            <tr>
                <td>Content</td>
                <td>Content</td>
                <td>Content</td>
            </tr>
            <tr>
                <td>Content</td>
                <td>Content</td>
                <td>Content</td>
            </tr>
        </tbody>
    </table>

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

How can I use CSS to transform a "+" symbol to an "x"?

When I created an accordion using HTML, JS, and CSS, I encountered a problem. The "+" sign in the accordion does not rotate correctly as it should. Instead of rotating from the middle of the "+" sign, it rotates from the top. This is my HTML code: <di ...

Can you please explain to me how to target a specific element by its ID in the DOM and then move on to the next element with the same ID using jQuery

During the event handling process, a scenario arises where two div elements end up having identical IDs within the DOM structure. While using JQuery, my objective is to specifically target the second occurrence of the div with the aforementioned ID in the ...

Using Crawler4j, Jsoup, and JavaScript to retrieve modified attribute values

Currently, I am utilizing Crawler4j and Jsoup for web crawling and it's performing well with HTML text. However, some vital contents have default values hardcoded in CSS and then dynamically adjusted through JavaScript. For instance, there's a e ...

Issue with non-responsive images in Bootstrap 3

Here is the bootstrap configuration that I am currently using: http://www.bootply.com/118172 I'm having an issue with the responsiveness of the image. It's not shrinking to match the height of the div on the left side. Can anyone help me trouble ...

What is the process for converting x and y coordinates to align with a fixed display?

When I make an API call, I am receiving X and Y coordinates in the following format: x: "-0.0120956897735595703" y: "0.147876381874084473" To display these coordinates on my minimap images, I have set their display to be absolute. The "left" and "top" pr ...

Creating a responsive table layout with CSS

I currently have the following code: .fiftyFiftySection { background-color: #000; } .odometer { font-size: 3em; text-align: center; } table td { column-width: 1000px; text-align: center; } @media (max-width: 500px) { table td { column ...

How to Align React Material UI Grid with Varying Row Counts in Each Column

Objective My goal is to design a component that showcases details about a device, including an icon and its current status. For instance: Approach I've Taken I am attempting to accomplish this by structuring a MUI Grid in the form of a 2x2 grid la ...

Guide on breaking a th tag as a line in a table using CSS

I'm attempting to achieve jQuery datatable-style responsiveness in an Angular table child component. I managed to separate the td and th separately using absolute and relative positions but encountered an issue where the th tag is not breaking at the ...

Can Bootstrap be used to create distinct spacing between table rows in a DataTable?

How can I achieve the look of separate table rows as shown in the image provided? I am currently using DataTables and bootstrap 5. I am looking to create visually distinct rows where the background is visible in between each row. Click here to view the i ...

Persistent Gap at the Top of the Page

I'm facing a simple issue that I can't seem to solve. At the top of my page, there's a white space about the width of a finger, and when inspecting it, nothing seems to be highlighted. @import url('https://fonts.googleapis.com/css?fa ...

Make multiple images in one row resize proportionally instead of wrapping them to the next line

My phone's screen is small and I want the three images to remain in the same row. In case they don't fit, they should shrink proportionately to maintain alignment (refer to image at the bottom). Consider the code snippet below: <div id="exam ...

Innovative Inter-Browser Link with a Distinct Shape

I am currently developing a web application that enables users to input content and then send it out to their phones. Everything is working smoothly, but I am facing an issue with the logo design. The logo in question is displayed as follows: On the left ...

Chrome does not allow the use of a CSS property for hover that has been used for animation

One issue I encountered is that when using a CSS property for animation and then also using the same property for a hover effect in Google Chrome, the hovering effect does not work properly. Below is the animation code: @keyframes fadeInUpBig { 0% { ...

Endless rotation with stunning magnification feature

My goal is to create a responsive carousel with auto-play infinite loop functionality, where the center item always occupies 70% of the viewport width. Currently, I have achieved a similar result using the Slick library: https://codepen.io/anon/pen/pBvQB ...

The functionality of the combobox in Vuetify differs from that of an input field

I have implemented Vuetify and am using its combobox component for search functionality on my website. However, I have noticed that the text value in the combobox only gets added to the watcher when the mouse exits the field. This behavior is not ideal f ...

What steps should I take to fix my responsive media query?

I am currently working on fixing some responsive issues on my WordPress website. Previously, in mobile view, it looked like this: https://i.stack.imgur.com/vpvHy.jpg After adding the following code to the CSS of my child theme: @media only screen a ...

What could be causing the side margins on my navbar in mobile view in Bootstrap?

After spending some time working on a simple navbar with CSS styling, I encountered an issue when viewing it in mobile mode. The navbar did not expand to 100% of the screen width and had a margin of about 20px on both sides. CSS .navbar .brand { wi ...

What is the best method to center a div on the screen?

Is there a way to have a div open in the center of the screen? ...

Need help creating perfect round buttons with bootstrap 4?

After incorporating this fiddle into my code, the goal was to design a circular button. View Fiddle Here The code provided is for bootstrap 3. However, when using it with bootstrap 4, the button ends up being square instead of circular. See example here: ...

Resolving the issue of "Cannot set properties of null (setting 'innerHTML') at HTMLInputElement.loader" involves identifying the root cause and implementing

Need assistance with this code. Although I believe everything is correct, it still isn't working as expected. The error mentioned in the title comes up whenever I try to use it. I've made multiple modifications to the code but it's still not ...