several tables all set to the identical TD width

Using a css sheet, I have formatted two tables. The first table is used for filter/sort selection, while the second table is a scrollable data table.


     div#scrollTableContainer {
     width: auto;
     margin: 20px; /* just for presentation purposes */
     border: 1px solid black;
     }

    #tHeadContainer {
        background: #CC3600;
        color: black;
        font-weight: bold;
    }
    #tBodyContainer {
        height: 750px;
        overflow-y: scroll;
    }
        td:first-child {
        min-width: 5%; /* EDIT */
        max-width: 5%;
        border-left:0;
    }

    td:first-child + td {
        min-width: 4%; 
        max-width: 4%;
    }

    td:first-child + td + td {
        min-width: 4%; 
        max-width: 4%;
    }

The alignment of columns in both tables is off, causing the Title/Header columns to not match the columns below. Additionally, the display differs between Chrome/IE and Firefox.

I am struggling to correct this issue, any assistance would be greatly appreciated.

Answer №1

div#scrollTableContainer {
  width: auto;
  margin: 20px;
  /* just for presentation purposes */
}

#tHeadContainer {
  background: #CC3600;
  color: black;
  font-weight: bold;
}

#tBodyContainer {
  height: 750px;
}

th:first-child, td:first-child {
  min-width: 15%;
  max-width: 15%;
  width: 15%;
}

td:first-child+td {
  min-width: 4%;
  max-width: 4%;
}

td:first-child+td+td {
  min-width: 4%;
  max-width: 4%;
}
<div id="scrollTableContainer">
  <div id="tHeadContainer">
    <table border="1" align="center" width="100%" cellpadding="0" cellspacing="0">

      <tr>
        <th bgcolor="<%=bgc0%>">USED</th>
        <th bgcolor="<%=bgc0%>">STATUS</th>
      </tr>
    </table>
  </div>

  <div id="tBodyContainer">
    <table border="1" align="center" width="100%" cellpadding="0" cellspacing="0">
      <td> stuff </td>
      <td> More stuff </td>
    </table>
  </div>
</div>

Answer №2

If you're looking to align the columns of both tables vertically right, I have a solution for you. I updated your CSS and noticed that you missed the "tr" in the second table.

Check out the updated code on this JSFiddle link.

#scrollTableContainer {
 width: auto;
 margin: 20px; /* added for presentation purposes */
 border: 1px solid black;
 }

#tHeadContainer {
    background: #CC3600;
    color: black;
    font-weight: bold;
}

#tHeadContainer th{
 width:50%; 
}

#tBodyContainer {
    height: 750px;
    overflow-y: auto;
}

.TableData{
   width:100%;
 }

.TableData td{
 width:50%; 
}

Answer №3

Try this out! You might notice a slight margin due to the scroll bar in the second table, but you can adjust it by inserting a tab into the first array with the scrollbar's width. I hope this solution works for you.

#scrollTableContainer {
width : 96%;
margin : auto;
border : 1px solid #ccc;
}

#tHeadContainer {
background-color : green;
width : 100%;
}

#tBodyContainer {
width : 100%;
height : 750px;
overflow-y : scroll;
}

#tHeadContainer table, #tBodyContainer table {
border-collapse : collapse;
width : 100%;
}

td, th {
border : 1px solid black;
}

tr {
width : 100%;
}

th:first-child, td:first-child {
min-width : 15%;
max-width : 15%;
width : 15%; /* Adjust this value to change the width of the first column */
}
<div id="scrollTableContainer">

<div id="tHeadContainer">
<table>
<tr>
<th>USED</th>
<th>STATUS</th>
</tr>
</table>
</div>

<div id="tBodyContainer">
<table>
<tr>
<td>Stuff</td>
<td>Some other stuff</td>
</tr>
</table>
</div>

</div>

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 impact does including a parent View Tag have on the styling in React Native?

Why does adding a View parent break my styles? Could React Native's View tag have default styles that I'm not aware of? Displayed below is the Button component along with screenshots demonstrating the difference when using and not using the View ...

excess white space appears in the mobile version

I recently completed a website using both materializecss and bootstrap platforms. While I know this may not be the best practice, it worked for my needs. However, I am facing an issue with the mobile view. When I reduce the viewport size, a margin appear ...

Bootstrap 4 - DropDown option - Element is positioned above the navigation bar

Currently facing an issue with the DropDown menu. Whenever I add padding to the DropDown menu (class - drop_link), it ends up pushing the entire element over the <nav>. I'm unsure of how to prevent this from occurring. I attempted to disable som ...

Designing a toggle button interface with Material UI

Looking to add a toggle button to my page. Here is an image of what I have in mind: https://i.sstatic.net/tiQAP.png Unable to find any material-ui component or API for this specific toggle button design. Considering building a custom toggle button with CS ...

Opacity filter malfunctioning

It seems that the filter: opacity property is not functioning as expected in IE8. Despite having used it successfully before, I am currently facing issues with its implementation. Strangely enough, Firebug does not display the filter rule at all; only norm ...

What steps can I take to ensure that my logos remain visible even when I close the menu and resize the window?

On my website, I have a menu of logos that are clickable. These logos always display except on smaller screens, where they need to be toggled to show using a hamburger menu. The menu toggles fine when it is on a smaller screen, but there is an issue when y ...

Is there a way to display additional data alongside form submissions that do not directly correlate with the form fields?

I am working on incorporating event registration functionality using CodeIgniter. The goal is to showcase event details and allow users to register for an event. For registration, users will be required to log in before proceeding. Once logged in, their i ...

Putting Images Next to Each Other - Arranging Them to Be Responsive

I have a pair of images on my webpage that I've aligned next to each other. To enhance the mobile user experience, I want these two images to stack on top of each other when viewed on smaller screens. If anyone can provide guidance on creating respon ...

Tips for inserting multiple numbers from a single row into separate options within a SELECT statement

Is there a way to create a select box with multiple options that are based on one row from my MySQL table? For example, <?php if(!empty($row['size'])) { ?> <label>Size</label> ...

Having trouble getting JavaScript to replace tags in HTML

I've been working hard to replace all the shared code in posts on my website, but I'm having trouble getting it to work. I want everything inside <pre><code></code></pre> tags to be colorized using CSS. Here's a sampl ...

Is there a way to include a minimize button on a MaterialUi Table enclosed in a Paper component for easy table reduction?

I am trying to add a minimize button to either minimize my MaterialUi Table or the Paper component that wraps it. Here is the code I have so far: <TableContainer component={Paper} style={{maxHeight:'inherit', maxWidth:'inherit', boxS ...

When using Jsoup, make sure to nest the <div> tag within an <a>

As per the findings in this response: Referring to HTML 4.01 guidelines, <a> elements are limited to inline elements only. Since a <div> is a block element, it should not be placed within an <a>. However... In HTML5, <a> elem ...

I seem to be having some trouble with my navigation roll-over menu bar, as

Help! I'm having trouble getting my navigation bar to properly overlap the main content on my website. If you could take a look here: that would be greatly appreciated. Please disregard the header position for now, as I am still deciding on its place ...

Background image spacing

Can anyone explain why there is extra space after my background image in this code snippet? (red line in image highlights the spacing issue) Even though the background image doesn't have this space, it seems to extend beyond where the black color ends ...

Submit your information discreetly

Is there a way to submit a form to an external website without it causing the page to reload? I am working on automatically logging users into their Google account without interrupting their browsing experience. The following code snippet allows me to pr ...

Enhance your navigation bar with hover styles in React Router Dom v6

I'm having an issue with my navbar where the active styles are overriding the hover state. I want to maintain my hover state styles even on the active nav link. How can I achieve this? Here is what's currently happening: Active nav styles (look ...

adjust the size of a form field to match the background image dimensions

I'm encountering an issue while trying to solve this particular challenge: My goal is to integrate a login box onto a full-screen image. Although I've come across numerous methods for incorporating an image into a form field, my task requires me ...

Preventing Canvas Image Disappearance with JavaScript's onload Event

My current issue involves adding an Image to my webpage. However, every time I hit the refresh button, the image disappears. After researching on Stack Overflow, it was suggested to include window.onload=yourDrawFunction() in the code. Despite following th ...

Place the Div directly above a distinct Div

Hey there! I'm currently working on positioning one div on top of another div programmatically (using javascript or css). These divs are completely separate and have the following structure: <div class="bottom"> <img src="image"></i ...

Auto-selecting the first item in a CSS menu when the switcher is tapped on mobile devices

Struggling with a responsive CSS menu on my website, . The switcher on mobile seems to automatically click the first item in the menu (Home) as I open it, redirecting me instantly. When setting the link to "#" everything is fine, but then I lose the home l ...