I am trying to make an organisational chart in HTML. The code is fairly simple, but I have some problems with the rendering in Chrome/Safari and Opera.
Here is what the result should look like, as it works in Firefox and IE:
Here is in Chrome and Safari
And here is in Opera:
The problem comes from the border-collapse: collapse property in CSS. If I use the old coding style cellspacing="0" cellpadding="0"it works more or less, but is not valid in HTML5.
I created a jsFiddle to show the problem: http://jsfiddle.net/aGVp4/7/
My HTML:
<table cellspacing="0" cellpadding="0">
<tr>
<td colspan="3"></td>
<td colspan="2" class="case"></td>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="3"></td>
<td colspan="2" class="case"></td>
<td colspan="3"></td>
</tr>
<tr>
<td></td>
<td colspan="3" class="right bottom"></td>
<td colspan="3" class="bottom"></td>
<td></td>
</tr>
<tr> <!-- No colspan here, to make the layout symmetrical -->
<td class="right"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="right"></td>
<td></td>
</tr>
<tr>
<td colspan="2" class="case"></td>
<td colspan="4"></td>
<td colspan="2" class="case"></td>
</tr>
</table>
And my CSS:
.orgchart {
border-spacing: 0;
border-collapse: collapse;
}
td {
width: 3em;
height: 1em;
}
td.case {
border: 1px solid black;
}
td.right {
border-right: 1px solid black;
}
td.bottom {
border-bottom: 1px solid black;
}
td.top {
border-top: 1px solid black;
}
The problems seems to be caused by different interpretations of the collapsing border model in browsers. The border conflict resolution is defined in terms of cells, not slots, and when you use colspan=3, one cell spans 3 slots.
The 2nd cell of the 2nd row has a solid bottom border, and the 2nd cell of the 3rd row has no top border. When borders collapse, solid wins none. But the cells are only partially adjacent, as they span different columns. Browsers hand this differently. Chrome makes the border span all the columns of the upper cell, whereas Firefox makes the border span only one column, the one that the cells share – which is more reasonable, but CSS 2.1 seems to leave the issue open.
I tried playing with border: hidden, which helps on Chrome but causes new problems on Opera.
It seems that there are two options. You could use the HTML attributes, if they do the job. Though declared obsolete and forbidden in HTML5 CR, the same document also requires continued support to them in browsers.
But a cleaner, and perhaps more robust, approach is to avoid the problem by adding more empty cells. This means dividing two 3rd row cells into two cells so that only one of them shares a border with the cell of the 2nd row. This makes the table even more grid-like, but not essentially more complex:
<table class="orgchart">
<tr>
<td colspan="3"></td>
<td colspan="2" class="case"></td>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="3"></td>
<td colspan="2" class="case" ></td>
<td colspan="3"></td>
</tr>
<tr>
<td></td>
<td colspan="2" class="bottom"></td>
<td class="right bottom"></td>
<td class="bottom" ></td>
<td colspan="2" class="bottom" ></td>
<td></td>
</tr>
<tr> <!-- No colspan here, to make the layout symmetrical -->
<td class="right"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="right"></td>
<td></td>
</tr>
<tr>
<td colspan="2" class="case"></td>
<td colspan="4"></td>
<td colspan="2" class="case"></td>
</tr>
</table>
Add a new empty row <tr></tr> under the colspan will fix this problem (not a beautiful solution but works).
I played with your jsfiddle, and found a hack to fix the issue in Chrome and Safari.
Also works on FF and IE, but didn't test on Opera.
Try this (jsfiddle):
td.bottom {
border-top: 1px solid white; // this is the hack
border-bottom: 1px solid black;
}
td.right.bottom {
border-top: none; // fix for IE
}
As this is a hack, it may not work as your chart grows complex, but hope this helps in short-term.
Related
I have spotted a strange issue with chrome when rendering table borders. I have four columns and I want the third column to have no borders. In Firefox it displays correctly, so that it looks like the first and second columns are a separate table from the fourth column, as you can see here:
However, in Chrome, the top border of the first columns extends right across all the other columns as you can see here:
This is what the html code is for this:
<tr style="border: none;">
<td style="width: 120px;">Surname</td>
<td style="width: 300px;">Bloggs</td>
<td style="border: none; width: 10px;"> </td>
<td rowspan="3" style="width: 100px;"><div class="studentimg" style="background-image:url('<%=strStudentPhoto%>');"></div></td>
</tr>
I know it is the first column that is cause the issue because I change the code to this:
<tr style="border: none;">
<td style="width: 120px;">Surname</td>
<td style="border-top: none; width: 300px;">Bloggs</td>
<td style="border: none; width: 10px;"> </td>
<td rowspan="3" style="border-top: none; width: 100px;"><div class="studentimg" style="background-image:url('<%=strStudentPhoto%>');"></div></td>
</tr>
and in Chrome it still shows as above, whereas in Firefox it now shows as only the first column have a top border, like this?
Anyone have any ideas how to fix this for Chrome?
Thanks
David
The following code (based on yours) does not show the problem you described in Chrome.
Note: I removed a lot of the inline styles, i removed the inline border from the trs, I applied rowspan="3" to the third cell in the first row and omitted the third cell in the following rows. For the rest of the settings see yourself in the snippet below:
table {
border-collapse: collapse;
}
td {
border: 1px solid #777;
}
<table>
<tr>
<td style="width: 120px;">Surname</td>
<td style="width: 300px;">Bloggs</td>
<td rowspan="3" style="border: none; width: 10px;"> </td>
<td rowspan="3" style="width: 100px;">
<div style="width:100px;height:100px;background:url(https://placehold.it/67x100/fc5) center center no-repeat;background-size:contain;"></div>
</td>
</tr>
<tr>
<td>Surname</td>
<td>Bloggs</td>
</tr>
<tr>
<td>Surname</td>
<td>Bloggs</td>
</tr>
</table>
The example below contains two tables, and each table includes two sections. Both tables and sections are structurally the same.
When the cells in the first table that are marked with class ".to-hide" are hidden by changing this class to ".hide" (shown in the second table), the resulting layout of the second table appears inconsistent; the cell "4" in the first section closes all gaps left by the hidden cells, but cell "4" in the second section leaves open gaps.
On Chrome 68.0.3440.106, the code snippet below shows how one cell "4" fill open gaps, but the other cell "4" does not. On Firefox 60.0.2, both cells "4" leave open gaps. The image below is taken on Chrome 68.
How can I ensure that visible cells in the table cover any gaps left by hidden cells, consistently, across browsers?
/* Styles to mark and hide marked cells. */
.to-hide { background-color: lightgray; }
.hide { display: none; }
/* Styles to make the tables in the code snippet look pretty. */
.left { display: inline-block; }
.right { display: inline-block; margin-left: 20px; }
table { background-color: yellow; }
td { padding: 0 1em; background-color: white; border: solid 1px gray; }
<div class="left">
Original table:
<table>
<tbody>
<tr>
<td rowspan="3">1</td>
<td rowspan="2">.<br/>2<br/>.</td>
<td class="to-hide">3</td>
<td>4</td>
</tr>
<tr>
<td class="to-hide">a</td>
<td class="to-hide">b</td>
</tr>
<tr>
<td colspan="3">A</td>
</tr>
<tr>
<td colspan="4">i</td>
</tr>
<tr>
<td rowspan="3">1</td>
<td rowspan="2">.<br/>2<br/>.</td>
<td class="to-hide">3</td>
<td>4</td>
</tr>
<tr>
<td class="to-hide">a</td>
<td class="to-hide">b</td>
<tr>
<td colspan="3">A</td>
</tr>
<tr>
<td colspan="4">i</td>
</tr>
</tbody>
</table>
</div>
<div class="right">
Shaded cells hidden (notice cells "4"):
<table>
<tbody>
<tr>
<td rowspan="3">1</td>
<td rowspan="2">.<br/>2<br/>.</td>
<td class="hide">3</td>
<td>4</td>
</tr>
<tr>
<td class="hide">a</td>
<td class="hide">b</td>
</tr>
<tr>
<td colspan="3">A</td>
</tr>
<tr>
<td colspan="4">i</td>
</tr>
<tr>
<td rowspan="3">1</td>
<td rowspan="2">.<br/>2<br/>.</td>
<td class="hide">3</td>
<td>4</td>
</tr>
<tr>
<td class="hide">a</td>
<td class="hide">b</td>
<tr>
<td colspan="3">A</td>
</tr>
<tr>
<td colspan="4">i</td>
</tr>
</tbody>
</table>
</div>
By hiding cells "a" and "b" rowspan="3" of cell "1" wants to occupy the same area like cell "i". Cell "i" can not span 3 rows since there are only 3 rows left and on the last row spans cell "i" all columns.
Forcing hidden cells to a size of 0 does not help.
.hide {
visibility: hidden;
width: 0;
height: 0;
padding: 0;
}
Taking hidden cells out of flow by position: absolute does not help either.
That the first section of the table still looks good (no gaps) must be some kind of error correction by browser.
Only by removing hidden cells from the table and changing the values for rowspan and colspan I was able to achieve the intended distribution of cells.
<tr>
<td rowspan="2">1</td>
<td>.<br/>2<br/>.</td>
<td>4</td>
</tr>
<tr>
<td colspan="2">A</td>
</tr>
<tr>
<td colspan="3">i</td>
</tr>
I'm trying to create table which looks like below:
I have tried using margin-right property ,and also border spacing ,colspan but not able to achieve it!
Here is my link to codepen:https://codepen.io/saisree/pen/jwwwEZ
<tr >
<td style="padding-top:10px;"colspan="2"class=" fixed text-center">
<span class=" border6 bold pull-left">2210 924-16(267) </span><span class="boxed1"></span></tr>
Any kind of help is highly appreciated.
You need two tds in each tr. In the first 4 rows you apply the attribute colspan="2" to the second td tag, in the rows after that you apply colspan="2" to the first td tag. That's basically all. So actually, there are three TDs in each row, but as each row has a td with a colspan, you only see two in each row.
The width will depend on the contents by default, but you can use width settings for the tds of course. You can not use margins on tds.
table {
border-collapse: collapse;
width: 60%;
margin: 0 auto;
}
td {
border: 1px solid #ddd;
min-width: 35%;
}
td:nth-child(2) {
min-width: 50%;
}
<table>
<tr>
<td>AAA</td>
<td colspan="2" ;>BBB</td>
</tr>
<tr>
<td>AAA</td>
<td colspan="2" ;>BBB</td>
</tr>
<tr>
<td>AAA</td>
<td colspan="2" ;>BBB</td>
</tr>
<tr>
<td>AAA</td>
<td colspan="2" ;>BBB</td>
</tr>
<tr>
<td colspan="2" ;>CCC</td>
<td>DDD</td>
</tr>
<tr>
<td colspan="2" ;>CCC</td>
<td>DDD</td>
</tr>
<tr>
<td colspan="2" ;>CCC</td>
<td>DDD</td>
</tr>
</table>
I have dotted line separating two rows of the table like below.
<table cellspacing="0">
<tr>
<td>Issue</td>
<td>Date</td>
</tr>
<td style="border-bottom: 1px dotted red;padding-top:2px;width:800px;"></td>
<tr>
<td>Theres is a issue with the code</td>
<td>09-28-2012</td></tr>
</table>
This is fiddler version. I want to align that date on line somewhere not at the end. How can I do that.
Add colspan = "2" to the td that has the dotted line. colspan and rowspan define how many columns or rows the cell spans, respectively.
Here's a modified version of your demo: little link.
<table cellspacing="0">
<tr>
<td>Issue</td>
<td >Date</td>
</tr>
<tr>
<td class="td"></td>
<td class="td"></td>
<tr>
<tr>
<td>Theres is a issue with the code</td>
<td>09-28-2012</td>
</tr>
</table>
CSS:
.td{
border-bottom: 1px dotted red;width:800px;padding-top:2px;
}
DEMO
Please try this:
<table cellspacing="0">
<tr>
<td>Issue</td>
<td>Date</td>
</tr>
<tr style="border-bottom: 1px dotted red;padding-top:2px;width:800px;"><td></td><td ></td></tr>
<tr>
<td>Theres is a issue with the code</td>
<td>09-28-2012</td></tr>
</table>
<table>
<tr>
<td>4px</td>
<td>4px</td>
<td>4px</td>
</tr>
<tr>
<td colspan="3">content</td>
</tr>
<tr>
<td>4px</td>
<td>4px</td>
<td>4px</td>
</tr>
</table>
I can't set the td's to 4px height using CSS.
Firstly, you cannot define a css class that starts with a number. Your rules dont apply because you set a class of "4px". Please validate.
Secondly, define a font-size so the font doesn't exceed four pixels.
Thirdly, if this isn't tabular data do not use a table for the job. See http://www.hotdesign.com/seybold/
HTML:
<table cellspacing="0" cellpadding="0" width="100%">
<tr class="four-px">
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="3">content</td>
</tr>
<tr class="four-px">
<td></td>
<td></td>
<td></td>
</tr>
</table>
CSS:
table, tr, td { background:#dd0;}
tr.four-px { height:4px; }
tr.four-px td { background:#ff9; font-size:4px; line-height:1; }
Live Demo: http://jsfiddle.net/D9pm9/11/
Live Demo with text inside rows: http://jsfiddle.net/D9pm9/12/
set the row's height.
<td>style="height:4px;"</td>
or...
<table>
<tr>
<td class="smallCell"></td>
<td class="smallCell"></td>
<td class="smallCell"></td>
</tr>
</table>
/* style sheet */
.smallCell
{
height: 4px;
}
They won't shrink to 4px if you have text or some other element inside them which is too large though.
TD's always expand to accommodate the content. So if your TD is to be 4px, your content inside will have to be 4px or less as well.
Consider TD dimensions as min-width/min-height in concept.
I don't think you can size a row to 4px if there is text in it.
You can, however, resize the text inside the td itself to shrink the cells:
<table>
<tr>
<td style="font-size: 4px;">4px</td>
<td style="font-size: 4px;">4px</td>
<td style="font-size: 4px;">4px</td>
</tr>
<tr>
<td colspan="3">content</td>
</tr>
<tr>
<td style="font-size: 4px;">4px</td>
<td style="font-size: 4px;">4px</td>
<td style="font-size: 4px;">4px</td>
</tr>
</table>