Customize TableRow Column Width - html

I have a HTML table.
1st row has 5 elements while 2nd row has only 3 elements.
Why 3 columns of the 2nd row gets the width same as width of respective columns in previous row?
I mean since there are only 3 columns in 2nd row, are they not supposed to auto-resize to fill the row?
I tried setting the width of 2nd column in 2nd row, but that ALSO increases width of 2nd column in 1st row, which I don't want.
Any help appreciated.
EDIT
Required output

Hey now used to colspan
as like this
<table width="100%" cellspacing="0" cellpadding="0">
<tr class="blue">
<td width="35%"></td>
<td width="15%">SignUp</td>
<td width="15%">Create Blog</td>
<td width="15%">Custimize Blog</td>
<td width="15%">Success</td>
</tr>
<tr>
<td colspan="5">
<table width="100%" cellspacing="5" cellpadding="0">
<tr>
<td class="blue2">Create Blog</td>
<td class="blue3">Custimize Blog</td>
<td class="blue4">Success</td>
</tr></table>
</td>
</tr>
</table>
Css
table tr td{
text-align:center;
}
.blue{
background:lightblue;
}
.blue2{
background:red;
}
.blue3{
background:blue;
}
.blue4{
background:green;
}
live demo http://tinkerbin.com/vqnhht02
and now change to width or height according to your design

Try this:
`<table width="100%" cellspacing="0" cellpadding="0">
<tr class="blue">
<td width="20%"></td>
<td width="15%"></td>
<td width="15%">SignUp</td>
<td width="15%">Create Blog</td>
<td width="15%">Custimize Blog</td>
<td width="15%">Success</td>
</tr>
<tr>
<td class="blue" colspan="2">Create Blog</td>
< td class="blue" colspan="2">Custimize Blog</td>
<td class="blue" colspan="2">Success</td>
</tr>
</table>`
Give the background color as per your need.
This width issue is fixed I think.

Related

Table width doesn't size correctly to % of container

I'm having trouble trying to use tables as cells ( for responsiveness ) in my code.
I have 2 pieces of code, the first one (the expected behavior I'm looking) is a table of 637px with 2 tds splitting the size with %, the size splits correctly, one cell gets 319px, and the other one 318px.
<table style="width: 637px;" cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td width="50.07849293563579%">THIS IS 319</td>
<td width="49.92150706436421%">THIS IS 318</td>
</tr>
</tbody>
</table>
The second (what my code looks like) is a main table with a td with 2 tables inside with float left and the same exact width used on the case 1. In this case table 1 is 318px, and table 2 is 318px. missing 1 pixel. where did it go? Am I doing anything wrong?
<table cellpadding="0" cellspacing="0" border="0" width="637px">
<tbody>
<tr>
<td style="width: 100%">
<table cellpadding="0" cellspacing="0" border="0" style="float: left; width: 50.07849293563579%;">
<tbody>
<tr>
<td>THIS IS 318</td>
</tr>
</tbody>
</table>
<table cellpadding="0" cellspacing="0" border="0" style="float: left; width: 49.92150706436421%;">
<tbody>
<tr>
<td>THIS IS 318</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
Is there anything I am missing?

Table nested in a rowspan table cell doesn't fill cell height in all browsers

rendering and code in chrome
I cannot figure out why the nested table (marked red) is not occupying the full height of the outer (marked green) table cell (that spans over 8 rows).
This used to work, but newer browsers don't let the nested table occupy the full height of the outer table cell. IE11 with compatibility view still shows this occupying the full height, all others don't. What do I need to change in the code? Adding height="100%" to the table doesn't help.
Code:
<tr>
<td class="NameColumnCaption" valign="top" bgcolor="#c0c0c0" style="height: 19px;">11:00</td>
<td class="weekdetails" bgcolor="#f0f0f0" rowspan="8" colspan="10" style="cursor:pointer" ondblclick="modifyMeeting("212&dispUser=Janice%20Elland&globObjID=", 9);" onclick="detailview("oneweek.asp?Q=Janice%20Elland&D=-4");hN(33);" onmousemove="sN(33)" onmouseout="hN(33)">
<table class="tdnor" width="100%" id="tbl" cellspacing="0" cellpadding="3" bgcolor="white">
<tbody>
<tr>
<td width="5" bgcolor="#99ccff" style="height: 19px;"><img src="b1.gif" width="2px" height="10px" border="0"></td>
<td class="WeekDetails" valign="top" style="height: 19px;">
<font color="#0000cc">11:15-15:15</font><br>
<font color="#000000">Supplier Meeting</font> (Lancashire)Janice Elland<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0"></table>
</td>
</tr>
</tbody>
</table>
</td>
<td valign="top" class="WeekDetails" bgcolor="#f0f0f0" colspan="10" onmousemove="sN(0)" onmouseout="hN(0)" onclick="Meeting2("&D=-2","11","Janice%20Elland");" style="height: 19px;"></td>
<td valign="top" class="WeekDetails" bgcolor="#f0f0f0" colspan="10" onmousemove="sN(0)" onmouseout="hN(0)" onclick="Meeting2("&D=-1","11","Janice%20Elland");" style="height: 19px;"></td>
<td valign="top" class="WeekDetails" bgcolor="#95cc68" colspan="10" onmousemove="sN(0)" onmouseout="hN(0)" onclick="Meeting2("&D=0","11","Janice%20Elland");" style="height: 19px;"></td>
<td class="NameColumnCaption" valign="top" bgcolor="#c0c0c0" style="height: 19px;">11:00</td>
</tr>
with additional div and table-layout: fixed as suggested:
screenshot
<tr>
<td class="NameColumnCaption" valign="top" bgcolor="#c0c0c0" style="height: 19px;">11:00</td>
<td class="weekdetails" bgcolor="#f0f0f0" rowspan="8" colspan="10" style="cursor:pointer" ondblclick="modifyMeeting("212&dispUser=Janice%20Elland&globObjID=", 9);" onclick="detailview("oneweek.asp?Q=Janice%20Elland&D=-5");hN(33);" onmousemove="sN(33)" onmouseout="hN(33)">
<div style="height: 100%; min-height: 70px;">
<table width="100%" id="tbl" cellspacing="0" style="table-layout: fixed;border:1px solid #404040;" cellpadding="3" bgcolor="white">
<tbody>
<tr>
<td width="5" bgcolor="#99ccff" style="height: 19px;"><img src="b1.gif" width="2px" height="10px" border="0"></td>
<td class="WeekDetails" valign="top" style="height: 19px;">
<font color="#0000cc">11:15-15:15</font><br>
<font color="#000000">Supplier Meeting</font> (Lancashire)Janice Elland<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0"></table>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td valign="top" class="WeekDetails" bgcolor="#f0f0f0" colspan="10" onmousemove="sN(0)" onmouseout="hN(0)" onclick="Meeting2("&D=-3","11","Janice%20Elland");" style="height: 19px;"></td>
<td valign="top" class="WeekDetails" bgcolor="#f0f0f0" colspan="10" onmousemove="sN(0)" onmouseout="hN(0)" onclick="Meeting2("&D=-2","11","Janice%20Elland");" style="height: 19px;"></td>
<td valign="top" class="WeekDetails" bgcolor="#f0f0f0" colspan="10" onmousemove="sN(0)" onmouseout="hN(0)" onclick="Meeting2("&D=-1","11","Janice%20Elland");" style="height: 19px;"></td>
<td class="NameColumnCaption" valign="top" bgcolor="#c0c0c0" style="height: 19px;">11:00</td>
</tr>
Update 2
I made a new table because the fiddle provided by OP was too cluttered. Fortunately, it illustrated what the problem was. The nested tables did not expand the full height of the rowspanned td, so a td with rowspan="8" had a table within that was only 2 rows high instead of 8 rows.
The most important things to know is this:
(For this example the td that has the nested table is: .parent)
Apply min-height: 100% and min-width: 100%; to .parent.
Comment out the td under the .parent(i.e. td in the same column) to the total of .parent's rowspan- 1
ex. <td class="parent" rowspan="5"...>
.parent is in the first column / third row.
comment out the next 4 td in:
first column / forth row
first column / fifth row
first column / sixth row
first column / seventh row
When you construct the nested table, you:
make as many <tr>s as the .parent's rowspan
each <tr> should have an equal amount of columns
don't have to bother with tbody
The following demo is annotated with comments designating what's required to get the desired effect. I use the term required loosely, because you may have to adjust certain measurements of course (i.e. padding, width, etc.)
https://plnkr.co/edit/u6CpPDDF3hMC5JI1S5BY?p=preview
Update 1
Since this concerns a table inside another table try:
<table style="table-layout: fixed; display: inline-table"....>
Use
.css file or <style> block
table {table-layout: fixed;}
OR
inline
<table style="table-layout: fixed; ....>
You'll probably need to append a div inside a cell and increase it's height in order to increase the table's height.
<td>
<div style="height: 100%; min-height: 70px;">
"Cell Content"
</div>
</td>
If your tables are generated and you can't modify the HTML before it's loaded (i.e. editing the code). It is possible to do so programmatically, let me know if you do and I'll help with that as well.

Make a <td> span the entire row in a table

I'm not new to HTML but haven't touched it for some good time and I've encountered an annoying problem.
I have a table with two rows.
I want the first row to have one column - means that it will span the entire row, and I want the second row to have three columns, each one 33.3% of the row's width.
I have this code for the table :
<table width="900px" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">check</td>
</tr>
<tr>
<td align="center">check</td>
<td align="center">check</td>
<td align="center">check</td>
</tr>
</table>
But what happens is weird, the first row has one column with the same size as the second row's first column, and whenever I change one of them, it changes the other one too.
If I give the first row's <td> the width value of 500px lets say, it sets the second row's first <td> to the same size.
What am I doing wrong ?
You should use the colspan attribute on the first row's td.
Colspan="3" will set the cell to flow over 3 columns.
<table width="900px" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" colspan="3">check</td>
</tr>
<tr>
<td align="center">check</td>
<td align="center">check</td>
<td align="center">check</td>
</tr>
</table>
You want to use the colspan attribute like this:
<table width="900px" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" colspan="3">check</td>
</tr>
<tr>
<td align="center" >check</td>
<td align="center">check</td>
<td align="center">check</td>
</tr>
</table>
If you're using JSX (React) it should be written like this. The s in colspan is capitalized and the value is a number instead of a string.
<td colSpan={3}>Text</td>
You can use colspan
<td align="center" colspan="3">check</td>
http://www.w3schools.com/tags/att_td_colspan.asp
Using colspan like this:
<tr>
<td align="center" colspan="3">check</td>
</tr>
By colspan you merge the following cells in a row to one. If you use 2 in your sample you get one cell with a width of the first two columns and the third is as the third in the rest of the table.
alter the first row with the below
<tr>
<td colspan="3" align="center">check</td>
</tr>

Reducing HTML Table Row Height

I have table with few rows. I want 1st and 3rd row height to be set to 1 px and the 2nd row to normal height. But my code is not working.
HTML CODE goes below
<table border="0">
<tr style="height:2px;" >
<td width="10"><hr></td>
</tr>
<tr style="height:20px;" >
<td width="10">Hello</td>
</tr>
<tr style="height:20px;" >
<td width="10"><hr></td>
</tr>
</table>
Could anyone please tell me how to do it ?
Note: I dont want borders to be used because i Want for certain rows i may or may not need the horizontal line inside the rows.
Add style="padding:0px; margin:0px;" to your hr and change the height of your third tr to 2px
You will have :
<table border="0">
<tr style="height:2px;" >
<td width="10px"><hr style="padding:0px; margin:0px;"></td>
</tr>
<tr style="height:20px;" >
<td width="10px">Hello</td>
</tr>
<tr style="height:2px;" >
<td width="10px"><hr style="padding:0px; margin:0px;"></td>
</tr>
</table>

Wrong column width when using table-layout:fixed

In my example jsfiddle I have two HTML tables. They are basically the same - same class, same content, everything. The only difference is the order of rows.
<style>
.tbl-lay-fixed {table-layout:fixed}
</style>
<table class="tbl-lay-fixed" border="1" width="100%">
<tr>
<td width="5%">xxxx</td>
<td width="95%">yyyyyyyyyy</td>
</tr>
<tr>
<td colspan="2" width="100%">xxxx</td>
</tr>
</table>
<table class="tbl-lay-fixed" border="1" width="100%">
<tr>
<td colspan="2" width="100%">xxxx</td>
</tr>
<tr>
<td width="5%">xxxx</td>
<td width="95%">yyyyyyyyyy</td>
</tr>
</table>
Table number 1 is displayed correctly - width of the cells is correct.
Table number 2 is displayed incorrectly - second row have two columns with witdh set as 5% and 95% accordingly, but instead it is displayed as 50% 50%.
Where is the problem? It is the same in all browsers.
This seems to work in Firefox at least
(changing bottom TD colspan to 20)
just remove "width="100%" <table class="tbl-lay-fixed" border="1" width="100%"> from the table class