HTML table borders being overlapped by cell borders - html

I have a HTML table I am displaying in a UIWebView on my ios app. The table looks sweet however the table border and the <tr> or cell borders is overlapping the main table border.
Here is an example:
I am using CSS to style these borders and adding it to the html as classes. This is what my style sheet looks like.
<style type='text/css'>table.tdat{border-collapse:collapse;border-color:#000000; border-style:solid; border-width:1px;}td{padding:2px; font-family:Helvetica; color:black; font-size:12pt; height:15pt; text-align:right; vertical-align:top; white-space:nowrap;}tr.cta td{font-family:Arial; color:black; font-size:12pt; height:15pt; text-align:right;vertical-align:top;white-space:nowrap;border:1px solid #eeeeee;}tr.top td { border-top: thin solid black; }tr.bottom td { border-bottom: thin solid black; }tr.ax td:first-child { border-left: thin solid black; border-right: thin solid black;} </style>
This is from a NSString and I'm not 100% sure on css formatting as I have only ever used it while making iOS apps.
And then I use that CSS like this:
<table frame="box" class="tdat">
<tr class="cta top ax">
<td>Position:</td>
<td width="20">1</td>
<td width="20">2</td>
<td width="20">3</td>
<td width="20">4</td>
<td width="20">5</td>
<td width="20">6</td>
<td width="20">7</td>
<td width="20">8</td>
</tr>
<tr class="cta bottom ax">
<td>Axis A:</td>
<td>4</td>
<td>3</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>3</td>
<td>3</td>
<td>2</td>
</table>

It's because you are setting borders on the top and bottom of the td, meaning that the side borders are going up an extra pixel The side borders show 'on top' of the top and bottom borders it seems. You can fix this with some tweaks. I'd add cellspacing="0" to the table HTML and remove border-collapse: collapse;. Then just style borders accordingly.
table.tdat{
/*border-collapse:collapse; remove */
border: 1px solid black;
}
td{
padding:2px;
font-family:Helvetica;
color:black;
font-size:12pt;
height:15pt;
text-align:right;
vertical-align:top;
white-space:nowrap;
}
tr.cta td{
font-family:Arial;
color:black;
font-size:12pt;
height:15pt;
text-align:right;
vertical-align:top;
white-space:nowrap;
border:1px solid #eeeeee;
border-top: 0; /* ADD */
border-bottom: 0; /* ADD */
}
/*tr.top td {
border-top: thin solid black; REMOVE
}*/
tr.bottom td {
/*border-bottom: thin solid black; REMOVE*/
border-top: 1px solid #eee;
}
tr.ax td:first-child {
/*border-left: thin solid black; REMOVE */
border-right: thin solid black;
border-top-color: black;
}
http://jsbin.com/IQuYIBI/1/edit

Related

Make table rows stack at the top of a table with a fixed height (leave unused space empty, table rows are dynamic)

Link to jsfiddle
<table class="cr-table">
<thead class="cr-th">
<tr>
<th>Your Item #</th>
<th>Product Description</th>
<th>U of M</th>
<th>Qty Ordered</th>
<th>Qty Shipped</th>
<th>Unit Price</th>
<th>Amount</th>
</tr>
</thead>
<tbody class="cr-tbody">
<tr>
<td colspan="7">
<span>Pre-text</span>
</td>
</tr>
<tr style="padding:0px;margin:0px">
<td><span>Code</span></td>
<td><span>Name</span></td>
<td><span>UoS id</span></td>
<td><span>Qty Ordered</span></td>
<td><span>Qty Shipped</span></td>
<td><span>Price</span></td>
<td><span>Subtotal</span></td>
</tr>
<tr style="padding:0px;margin:0px">
<td><span>Code</span></td>
<td><span>Name</span></td>
<td><span>UoS id</span></td>
<td><span>Qty Ordered</span></td>
<td><span>Qty Shipped</span></td>
<td><span>Price</span></td>
<td><span>Subtotal</span></td>
</tr>
<tr>
<td colspan="7">
<span>Post-text</span>
</td>
</tr>
</tbody>
css:
.cr-table {
width: 100% !important; height: 50%; font-size: 11px !important; border: 1px solid black !important;
padding:0px !important;margin: 0px !important;
}
.cr-tbody {border: 1px solid black !important; font-size: 11px; height: 50%; border-collapse: collapse;}
.cr-th {font-size: 13px;border: 1px solid black; color: white; background-color: #829BAE;}
.cr-title {font-size: 22px; text-align: right; margin-right: 5%; font-weight: bold }
.cr-cell-name {font-size: 11px;background-color: #829BAE; border: 1px solid black; color: white; text-align: center}
.cr-cell-content {font-size: 11px; border: 1px solid black; text-align:center;}
.cr-td-foot {border-top: 0px;border-bottom:0px;border-right: solid black 1px;font-size: 11px;padding:3px}
.cr-td-foot-ri {border-top: 0px;border-bottom:0px;font-size: 11px;padding:3px}
.cr-address {padding-left: 0px; font-size: 11px; padding-top: 7px; padding-bottom: 7px; text-align: left !important}
.cr-ref {border: 2px solid red;}
.cr-top {border: 0px}
.cr-empty {color: white}
table.fixed { border-collapse: collapse; page-break-inside: avoid; table-layout:fixed; border: 1px solid black; width: 100% }
table.fixed td { overflow: hidden; border-collapse: collapse; }
I've added a link to a jsfiddle, where I've stripped down my code to a more simple example. Basically the rows with "Code Name UoSid etc.." are invoice lines and there can be one or more. I need the table to be of a certain size, but the rows should always be compactly stacked from the top down. In the jsfiddle you can see that they take up the whole table space and spread out evenly. In the masterpiece below you can see what I have on the left and what I need on the right.
It seems you are missing to apply style for TD in body of table. I would like to suggest you to option to solve issue :
If you want text-align left from top to down then add this to css :
.cr-tbody td{border-left:2px solid rgba(255,255,255,0);}
If you want text to be center in each td then add this to css:
.cr-tbody td{border-left:2px solid rgba(255,255,255,0);text-align:center;}
Hope this help you to solve your issue.

HTML, remove border from top-left cell of a table

I have a html table, my top-left cell is empty and I want to remove its border.
I tried with some css:
.border-less {
border-top: 1px solid #FFFFFF;
border-left: 1px solid #FFFFFF;
}
That I applied to my top left cell:
<td class="border-less"></td>
but it doesn't work.
Any idea how to achieve this?
Remove border from table and tr and apply border only for td.
table {
border-collapse: collapse;
}
td {
border: 1px solid grey;
}
td.border-less {
border: none;
}
<table>
<tr>
<td class="border-less"></td>
<td>22</td>
<td>33</td>
</tr>
<tr>
<td>11</td>
<td>22</td>
<td>33</td>
</tr>
<tr>
<td>11</td>
<td>22</td>
<td>33</td>
</tr>
</table>
Try like this: Demo
table tr.border-less>td {
border-top: 0px solid #FFFFFF;
border-left: 0px solid #FFFFFF;
}
check out this
CSS
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
.border-less {
border-top: 1px solid #FFFFFF;
border-left: 1px solid #FFFFFF;
}
http://jsfiddle.net/vasanthanvas/jfvhxy59/

Remove specific td border?

I'm wondering why this is rendering correctly with or without the .container in css color: red;. What's going on behind the code and how will I achieve the second image without removing the .container?
.container table {
border-collapse: collapse;
border: solid 1px #000;
}
.container table td {
border: solid 1px #000;
}
.no-border-right {
border-right: solid 1px #FFF;
color: red;
}
<div class="container">
<table>
<tr>
<td class="no-border-right">One</td>
<td>Two</td>
</tr>
<tr>
<td>One</td>
<td>Two</td>
</tr>
</table>
</div>
you can do
.container table td.no-border-right {
border-right: solid 1px #FFF;
color: red;
}
.container table td has more specificity than .no-border-right
It's better not to use !important unless absolutely necessary as. First work within the rules of specificity as best as you can
Checkout this guide and this calculator of specificity
.no-border-right {
border-right: solid 1px #FFF !important;
color: red;
}
Just use border-right: solid 1px #FFF!important;
.container table {
border-collapse: collapse;
border: solid 1px #000;
}
.container table td {
border: solid 1px #000;
}
.no-border-right {
border-right: solid 1px #FFF!important;
color: red;
}
<html>
<head>
<title></title>
<style type="text/css">
</style>
</head>
<body>
<div class="container">
<table>
<tr>
<td class="no-border-right">One</td>
<td>Two</td>
</tr>
<tr>
<td>One</td>
<td>Two</td>
</tr>
</table>
</div>
</body>
Here is a Solution.
The key css property is border-collapse:collapse;. You can read more here.
table {
border-collapse:collapse;
border:1px solid black;
}
td {
border-right:1px solid black;
border-bottom:1px solid black;
}
.no-border-right{
border-right:none;
}
Growing an ugly duckling into a swan
Step 1 - Increasing specificity
Placing .container before .no-border-right will increase its specificity, but looks ugly! Look at these ugly gaps:
Step 2 - Beautify your table
Let's go one step further and make this:
In order to remove those gaps, let's:
Use the default border-collapse: separate
Use border-spacing: 0 to remove the default gaps between cells
Place the top and left border on the table itself
Place the right and bottom border on the cells
Remove the right border on .no-border-right and the left border on the cell next to it (targeted with the adjacent selector +)
Working Example
.container table {
border-spacing: 0;
border-top: solid 1px #000;
border-left: solid 1px #000;
}
.container table td {
border-right: solid 1px #000;
border-bottom: solid 1px #000;
}
.container .no-border-right {
border-right: none;
color: red;
}
.container .no-border-right + td {
border-left: none;
}
<div class="container">
<table>
<tr>
<td class="no-border-right">One</td>
<td>Two</td>
</tr>
<tr>
<td>One</td>
<td>Two</td>
</tr>
</table>
</div>
CSS gives a higher priority to selectors with parents, therefore nullifying the order in the document.
Simple fix: replace your ".no-border-right" selector with ".container table td.no-border-right".

Tables border HTML+CSS

I'm having this weird little problem I can't get my head wrapped around.
What it needs to do is:
table with 3 cells, no/white borders except the top border of all cells and the left and right border of the middle cell.
Here is the code:
CSS:
table{
font-family: verdana,arial,sans-serif;
font-size:11px;
border-width: 1px;
border-collapse: collapse;
}
table td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-top-color:#000000;
border-right-color:#FFFFFF;
border-bottom-color:#FFFFFF;
border-left-color:#FFFFFF;
}
table td.centercell {
border-width: 1px;
padding: 8px;
border-style: solid;
border-top-color: #000000;
border-right-color:#000000;
border-bottom-color:#FFFFFF;
border-left-color:#000000;
z-index:10;
}
HTML:
<table>
<tr>
<td>Info Header 1</td>
<td class="centercell">Info Header 2</td>
<td>Info Header 3</td>
</tr>
</table>
Does anybody have any idea why I can't get it fixed?
It's the border-collapse on the table that's doing the damage. Obviously you're still going to need that so . . .
Add a border-right to the first cell and only border-right to the second.
table td.centercell {
border-width: 1px;
padding: 8px;
border-style: solid;
border-top-color: #000000;
border-right-color:#000000;
z-index:10;
}
td:first-child{
border-right: 1px solid #000000;
}
Fiddle here : http://jsfiddle.net/7t85q/
So instead of using #FFFFFF, use transparent
Then set the border-right of the td
td {
border-right:1px solid #000;
}
td:last-of-type {
border-right 1px solid transparent
}
I believe this is what you're looking for: http://jsfiddle.net/2F8vF/2/
Even though centercell has it's own class, it's still a table td class as well. So it was grabbing some CSS that you didn't want.
table td {
padding:8px;
border-top: 1px solid #000;
border-left:0px;
border-right:0px;
border-bottom:0px;
}
table td.centercell {
border-left:1px solid #000;
border-right:1px solid #000;
}

border-color change in table cells

I have a very simple HTML table like below:
<table>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr><!-- Table Row -->
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</tbody>
</table>
that I want when I hover on each of the cells, the borders of the cell could change color. So I wrote the following CSS trying to achieve the effect:
table{
position: absolute;
font-family:Arial, Helvetica, sans-serif;
color:white;
font-size:12px;
border:white 1px solid;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
-moz-box-shadow: 0 1px 2px #d1d1d1;
-webkit-box-shadow: 0 1px 2px #d1d1d1;
box-shadow: 0 1px 2px #d1d1d1;
width: 100%;
height: 100%%;
}
table tr {
text-align: center;
padding-left:20px;
}
table td {
padding:18px;
border-top: 1px solid #ffffff;
border-bottom:1px solid #e0e0e0;
border-left: 1px solid #e0e0e0;
width: 33%;
height: 50%;
background-color: black;
}
table td:hover{
border:blue 1px solid;
}
This code works, but not perfectly. It works great when I hover on the cells 1, 2, 3 (as numbered in the html), BUT when I hover, for example, on cell 4 5 6, the top border of the cell is not showing blue. I think the top borders of them are overlayed by the bottom borders of the cells above.
Is there a work around to this issue?
With border-collapse set to collapse, the solution would be to use an inset border for all the cells, and a solid border for the cell that the mouse hovers over. Here's the suggested CSS in action: http://jsfiddle.net/QmHGG/
The following is the CSS that was applied to the table:
table, tr, td {
border: 1px inset black;
border-collapse: collapse;
border-spacing: 0;
}
td:hover {
border: 1px solid red;
}