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;
}
Related
I'm trying to draw an almost S-shaped line between the the left and right columns below.
The line will be vertical in rows 2 and 3. The top of line will curve right, around the top-left of the number 2. The bottom of the line will curve left, around the bottom right of number 7.
<code>
<table class="col">
<tr><td>1</td><td class="tl">2</td></tr>
<tr><td>3</td><td class="l">4</td></tr>
<tr><td>5</td><td class="l">6</td></tr>
<tr><td class="br">7</td><td>8</td></tr>
</table>
</code>
I've tried using both box-shadows and borders but cannot create a solid line with no gaps.
How can I create a solid line with this shape?
Note, I can only use HTML and CSS as it's for an epub file.
CSS code using box-shadow. The shadows do not join up.
.tl {
border-top-left-radius: 10px;
box-shadow: -1px 0 0 1px black;
}
.l {
box-shadow: 0 0 0 1px black;
clip-path: inset(1px 0 0 -1px);
}
td.br {
border-bottom-right-radius: 10px;
box-shadow: 1px 1px 0 1px black;
}
table.col {
border-collapse: separate;
border-spacing: 1px;
border: 0;
}
CSS code using borders. The line is continuous most of the way. However there there is a slight horizontal jump of the line, between 3rd and 4th rows.
td.br {
border-bottom-right-radius: 10px;
border-bottom: solid 1px black;
border-right: solid 1px black;
}
td.tl {
border-top-left-radius: 10px;
border-top: solid 1px black;
border-left: solid 1px black;
}
.l {
border-left: solid 1px black
}
table.col {
border-collapse: separate;
border-spacing: 0;
border: 0;
}
HTML code
<table class="col">
<tr>
<td>1</td>
<td class="tl">2</td>
</tr>
<tr>
<td>3</td>
<td class="l">4</td>
</tr>
<tr>
<td>5</td>
<td class="l">6</td>
</tr>
<tr>
<td class="br">7</td>
<td>8</td>
</tr>
</table>
My border radius does not show if I have the property of border-collapse on the table tag. I need the border-radius property on and if I remove the border-collapse property I don't get the look I want which is the grey sections to go to the very edge of the table.
What is the solution to this and whats the cause of it?
Thanks in advance
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
table {
/*if i comment out the border-collapse property it then shows my radius*/
border-collapse: collapse;
margin: 25px 0;
width: 50%;
border-radius: 5px;
font-size: 1.4rem;
min-width: 400px;
border: 1px solid #c3c3c3;
/*margin is just for demo*/
margin: 20px 20px;
}
table tr {
border-bottom: solid 1px #d1d1d1;
}
table tr:nth-child(odd) {
background-color: #eee;
}
table td {
padding: 10px 15px;
}
table td:first-of-type {
font-weight: 600;
}
<table>
<tbody>
<tr>
<td>Application</td>
<td>Natural gas & LPG</td>
</tr>
<tr>
<td>Standards</td>
<td>BS EN ISO 9001:2008 - EN 331:1998</td>
</tr>
<tr>
<td>Connection</td>
<td>BSP Taper F</td>
</tr>
<tr>
<td>Finish</td>
<td>Plated</td>
</tr>
</tbody>
</table>
very
If your intention is to not see any spacing between the content background and the border, then simply remove the border-collapse and add border-spacing: 0. border-spacing: 0 will not affect the border radius at all and it will also give you the results of no space between the border and the inner content.
In searching it seems there are some anomalies with using collapse and radius together. There are also some work arounds where you use psuedo tags on the tables children specifically to get a radius to work, but why waste all that time when you can just remove the space between the border and its inner content using border-spacing which works well with border-radius
EDIT: By using psuedo selectors along with border-space: 0 you can achieve a more pronounced border radius.
We want to target each td element that borders the edge of the table element.
table tr td:first-of-type and table tr td:last of type to get the left and right sides. Then we target each subsequent first and last child to get the corners. Lastly, if this is a dynamic table and you will have more than two data tables located in the table, add td:not(:first-child):not(:last-child) on each first and last of type.
I don't get the look I want which is the grey sections to go to the very edge of the table.
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
table {
/*add border-spacing: 0 instead of border-collapse: collapse*/
border-spacing: 0;
margin: 25px 0;
width: 50%;
font-size: 1.4rem;
min-width: 400px;
/*margin is just for demo*/
margin: 20px 20px;
}
/* Start psuedo child tags here, targeting each data elements relevant corners and sides */
table tr td:first-of-type {
border-left: 1px solid #c3c3c3;
}
table tr td:last-of-type {
border-right: 1px solid #c3c3c3;
}
/* :not(:first-child):not(:last-child)
This will get any potential data tables that are added
that are not sides or corners however, they are border
data tables on top or bottom */
table tr:first-of-type td:not(:first-child):not(:last-child){
border-top: 1px solid #c3c3c3;
}
table tr:last-of-type td:not(:first-child):not(:last-child){
border-bottom: 1px solid #c3c3c3;
}
table tr:first-of-type td:first-child {
border-top: 1px solid #c3c3c3;
border-top-left-radius: 5px;
}
table tr:first-of-type td:last-child {
border-top: 1px solid #c3c3c3;
border-top-right-radius: 5px;
}
table tr:last-of-type td:last-child {
border-right: 1px solid #c3c3c3;
border-bottom: 1px solid #c3c3c3;
border-bottom-right-radius: 5px;
}
table tr:last-of-type td:first-child {
border-left: 1px solid #c3c3c3;
border-bottom: 1px solid #c3c3c3;
border-bottom-left-radius: 5px;
}
/* End Psuedo tags here */
table tr {
border-bottom: solid 1px #d1d1d1;
}
table tr:nth-child(odd) {
background-color: #eee;
}
table td {
padding: 10px 15px;
}
table td:first-of-type {
font-weight: 600;
}
<div id="table">
<table>
<tbody>
<tr>
<td>Application</td>
<td>here is some data</td>
<td>Natural gas & LPG</td>
</tr>
<tr>
<td>Standards</td>
<td>some data in between</td>
<td>BS EN ISO 9001:2008 - EN 331:1998</td>
</tr>
<tr>
<td>Connection</td>
<td>some data in between</td>
<td>BSP Taper F</td>
</tr>
<tr>
<td>more tables</td>
<td>some data in between</td>
<td>more data</td>
</tr>
<tr>
<td>some more data still</td>
<td>some data in between</td>
<td>and yet more about this data</td>
</tr>
<tr>
<td>Finish</td>
<td>Plated</td>
<td>Plated too</td>
</tr>
</tbody>
</table>
</div>
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".
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
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;
}