HTML tables - How to make the child table's columns have the same width as it's parent table columns?
-
So, I have a table within a table (inside a td). This child table has exactly the same number of columns as the parent table. The only problem is, the child table's columns aren't the same width as the parent table's columns. This is how it looks like: How should I style the child table? Is there a predefined way to fix this? Or do I need to write a "normalization" function via jquery which will change the width of columns on page load?
-
Answer:
function normaliseWidth(id) { iter = 1; $("#splitForm" + id + " td").each(function() { //alert($(this)); $(this).width($("#" + id + " td:nth-child(" + iter + ")").width()); ++iter; }); } I just iterated through all the td's and changed their width to parent's width. This seems to have fixed it. I'm hoping there won't be any side effects to this. Thanks for all the help.
Tool at Stack Overflow Visit the source
Other answers
Why do you need to create another table if they have the same number of columns. You should just add a row instead of another table. That way your column will be the same. The problem is the content of your inner table is pushing cells width.
Etienne Carrier
The answer is a couple different things. the fastest way would be to add classes to each column (and make sure they pair up between parent/child). I usually use a "col-" prefix. Set your widths to the classes and you should be a lot closer. Also be sure to remove any borders, paddings, margins, etc. if it still isnt quite right look into http://www.w3schools.com/cssref/pr_tab_border-collapse.asp
PseudoNinja
If you are forced to do it that way, either specify the width of each column explicitly using CSS or the HTML attribute in both tables. You could also write javascript code that happens after the page is loaded to adjust the size of the columns of that top table to match the bottom table. You're mileage may vary with this approach. Your comment in another answer about needing a form for each row makes me think you could modify your layout to put the form around the table and combine the two tables to have the header and data rows in the same table. Then make some backend code changes to handle the posts differently.
slolife
Column Column What is that Column Column Column Column Column Are you okay Column Column Column Column Column I am fine Column2 Column2 Column2 Column2 Column2 Column2 Column2 Column2 Column2 Column2 Column2 Column2 What about you ? Is everything alright ? Data Data Data Data Data Data Hope this works too, hehe Data Data Data Data Data Data
Gagandeep Bali
Related Q & A:
- How to skip columns empty in CSV file when importing into MySQL table using LOAD DATA INFILE?Best solution by Stack Overflow
- How to make a dynamic table in PHP?Best solution by Stack Overflow
- How can I make my interests table transparent on Myspace?Best solution by Yahoo! Answers
- How to make free mobile call's from internet?Best solution by Yahoo! Answers
- How to make your own black table default layout?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.