Table with rounded border using CSS - html

I have an issue. I have a table made with pure HTML code, here is it:
<table id="calendarTable">
<tr>
<th id="tableHeader" colspan=7></th>
</tr>
<tr>
<th>Dom</th>
<th>Seg</th>
<th>Ter</th>
<th>Qua</th>
<th>Qui</th>
<th>Sex</th>
<th>Sáb</th>
</tr>
<tbody id="tableBody"></tbody>
<tr>
<td colspan=7>
<p>
<form id="dateChooser" name="dateChooser">
<select name="chooseMonth" onChange="populateTable(this.form)">
<option selected>Janeiro
<option>Fevereiro
<option>Março
<option>Abril
<option>Maio
<option>Junho
<option>Julho
<option>Agosto
<option>Setembro
<option>Outubro
<option>Novembro
<option>Dezembro
</select>
<select name="chooseYear" onChange="populateTable(this.form)">
</select>
</form>
</p>
</td>
</tr>
</table>
Here is my CSS:
#calendarTable {
text-align: center;
width: 80%;
height: 100%;
color: #18B6E6;
border-color: #18B6E6;
border: solid 1px;
border-radius: 20px;
}
#calendarTable td {
border: solid 1px;
border-radius: 4px;
}
#calendarTable th {
border: solid 1px;
font-weight: 700;
}
I want to round the borders using only CSS, I just tried using the border-radius property but my table is not changing borders.
Anyone have a tip for me?
Thanks in advance!

Here's a simplified table with border radius applied. The trick is to set the left border of the cell rather than the table itself. It'll work with or without a thead and I've annotated the css to show what I'm doing.
/*
* First normalise some of the attributes
*/
table td,
table th {
padding: .5rem;
text-align: left;
vertical-align: top;
}
/*
* Add the border, set border spacing etc
* The left width is 0 so cell border can be applied without doubling up.
*/
.table-bordered {
border: 1px solid silver;
border-left-width: 0;
border-collapse: separate;
border-spacing: 0;
border-radius: 1rem;
}
/*
* Add the border to table cell/header
*/
.table-bordered td,
.table-bordered th {
border-top: 1px solid silver;
border-left: 1px solid silver;
}
/*
* Remove the top border from the first header/cell
*/
.table-bordered tbody:first-child tr:first-child td,
.table-bordered thead:first-child tr:first-child th {
border-top-width: 0;
}
/*
* Set the border radius for the first header/cell
*/
.table-bordered thead:first-child tr:first-child td:first-child,
.table-bordered thead:first-child tr:first-child th:first-child {
border-top-left-radius: 1rem;
}
/*
* Set the border radius for the last header/cell
*/
.table-bordered tbody:last-child tr:last-child td:first-child,
.table-bordered tbody:last-child tr:last-child th:first-child {
border-bottom-left-radius: 1rem;
}
<table class="table-bordered">
<thead>
<tr>
<th scope="col">Header</th>
<th>Header</th>
<th>Header</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Data</th>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<th scope="row">Data</th>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<th scope="row">Data</th>
<td>Data</td>
<td>Data</td>
</tr>
</tbody>
</table>

As others have said, this is the code that should give the look you want.
Code
#RoundedTable {
border: 1px solid black;
border-radius: 10px;
}
#RoundedTable td, #RoundedTable th {
border: 1px solid gray;
border-radius: 10px;
padding: 3px;
}
<table id="RoundedTable">
<tr><th>Table header</th><th>Another header cell</th></tr>
<tr><td>Table cell...</td><td>More data...</td></tr>
<tr><td>Table cell...</td><td>More data...</td></tr>
<tr><td>Table cell...</td><td>More data...</td></tr>
<tr><td>Table cell...</td><td>More data...</td></tr>
</table>
Caveat
For this to work, though, you need to make sure that border-collapse is set to separate instead of collapse for your table. Otherwise, neither the radius for the cells nor the radius for the whole table will work.
So look through the other CSS that may be affecting your table. If you find border-collapse: collapse; anywhere, that's the problem.

#calendarTable{
border-radius:20px;
}
DEMO

Remove the border attribute on the table. It is still supported in browsers, but it is removed from HTML5 specification. The effect that attribute makes is probably not what you want anyways.
If you want border around each cell in your table just specify that in CSS and include border-radius there as well.
I.e.
#calendarTable td { border: solid 1px; border-radius: 4px; }
If you just want border around the whole table, use the same css on table selector:
#calendarTable { border: solid 1px; border-radius: 4px; }

border-radius seems to work both on table and td elements, with or without the border attribute on table.
You must have some other CSS rules coming into play.
table {
border: 1px solid blue;
border-radius: 10px;
}
table td, table th {
border: 1px solid gray;
border-radius: 10px;
padding: 5px;
}
<table border=1>
<tr>
<th>Table header...</th>
</tr>
<tr>
<td>Table cell...</td>
</tr>
<tr>
<td>Table cell...</td>
</tr>
<tr>
<td>Table cell...</td>
</tr>
<tr>
<td>Table cell...</td>
</tr>
</table>

Related

Add specific border styling and spacing that differs for the table, tr and cells

I was wondering if it was possible, with html and/or CSS, to collapse only tr with he table's outline, while having different border styles for the table's outline and trs, and the tds and ths.
I know this is complicated, so if this can make it clearer, here's a drawing of what I'm trying to achieve:
No, border-collapse applies only to the whole table, and it is not a valid property for tr or td elements so you cannot apply it to those to get a different spacing.
However you can “fake” it by adding the cell content into a div and using it for some of the styling:
Apply the outer table styling to the table as normal
Apply the row styling to the top and bottom borders of the th / td cells
Apply the "cell" styling to the divs inside the th & tds.
Working Example:
table {
border: 6px solid lightgray;
border-right-color: gray;
border-bottom-color: gray;
border-collapse: collapse;
}
td {
border-top: 5px solid gray;
}
tr:not(:last-child) td{
border-bottom: 5px solid gray;
}
th .cell,
td .cell {
margin: 5px;
padding: 5px;
border: 2px ridge lightblue;
}
<table>
<tr>
<th><div class="cell">First Name</div></th>
<th><div class="cell">Last Name</div></th>
</tr>
<tr>
<td><div class="cell">John</div></td>
<td><div class="cell">Smith</div></td>
</tr>
<tr>
<td><div class="cell">Jane</div></td>
<td><div class="cell">Doe</div></td>
</tr>
</table>
Found a way by just adding an hr and a minuscule tr between both trs.
hr {
border: 4px outset rgb(207, 172, 179);
width: 443px;
position: absolute;
top: 388px;
left: 35px;
}
tr#mini {
border: none;
padding: 0px;
margin: 0px;margin-top: 0px;
margin-bottom: 0px;
height: 8px;
}
HTML:
<table id="tableau" class="nomaltext">
<tr>
<th>
25g
</th>
<th>
50g
</th>
<th>
75g
</th>
<th>
100g
</th>
<th>
Personnalisé (min. 120g)
</th>
</tr>
<tr id="mini">
<hr>
</tr>
<tr>
<td>
5,99$
</td>
<td>
8,99$
</td>
<td>
13,80$
</td>
<td>
7,40$
</td>
<td>
11¢/gramme
</td>
</tr>
</table>

How do I change border color of a single table row?

I'm trying to highlight a table row by changing the border color of that individual row. This is my CSS:
table { border-collapse: collapse;}
td { min-width: 100px; border: 1px solid green; }
.highlight td { border: 1px solid orange; }
...and this is my HTML:
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr class="highlight">
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
</table>
The result is this:
The top border remains green. The only way I could get it work was by changing border-bottom color of the TD elements 1 and 2. Is there a more elegant solution? Using the outline property didn't do the trick. Thanks!
Only by removing border-collapse: collapse; because it merges borders that are adjacent.
Then apply a 0 value for border-spacing
Border-spacing : MDN
The border-spacing CSS property specifies the distance between the borders of adjacent table cells (only for the separated borders model). This is equivalent to the cellspacing attribute in presentational HTML, but an optional second value can be used to set different horizontal and vertical spacing.
table {
/*border-collapse: collapse;*/
border-spacing:0;
font-size:32px;
}
td {
min-width: 100px;
border: 3px solid green;
}
.highlight td {
border-color: orange;
}
/* optional enhancment to narrow vertical joined borders*/
td + td {
border-left:0;
}
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr class="highlight">
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
</table>
try that
table { border-collapse: collapse;}
td { min-width: 100px;}
td:first-child{border-right: 1px solid green;}
tr{border: 1px solid green;}
tr.highlight td { border: 1px solid orange; border-top: 1px solid orange; }
you should give the border to the rows and the td that are first child, then apply different color for the border of the highlited tr.
In order to fix this give your tr a display property of block. See the code snippet below.
table {
width: 100%;
border-collapse: collapse;
}
tr {
width: 100%;
display: block;
}
td {
min-width: 100px;
text-align: center;
border: 1px solid green;
/*
Remove the left border from td
to make the border width even
on all sides.
*/
border-left: none;
}
td:first-child {
/*
If the td is the first child
give it a left border to close
the left side of the row.
*/
border-left: 1px solid green;
}
.highlight td {
/*
Since you're changing only the
border-color, you only need to
redefine the border-color.
*/
border-color: orange;
}
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr class="highlight">
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
</table>
Alternatively, if you set the width of tr to 100%, which I have in the script, you can use inline-block or inline-flex for your display property.
/*
In the case of the tr with a width of 100%
all of the following have the same output
for their borders.
*/
display: inline-block;
display: inline-flex;
display: block;

HTML table cell spacing - only between cells, no outer one

I am trying to add cell spacing to a html table.
I want to add spacing between cells without the outer spacing.
My problem is, that the cellspacing html attribute and border-spacing CSS property adds spacing outside too.
I would like to put cell spacing without the red (outer) part - only the yellow one.
Is it possible?
Edit:
The image was drawn by hand (MS-Paint) only for illustration.
The coloring is for debugging - so that one can see where the borders, and spacing is.
I have found a roundabout solution including some additional div-s:
.inner-spacing {
border-collapse: collapse;
background-color: yellow;
border: 2px solid black;
}
.inner-spacing td {
padding: 0;
}
.inner-spacing td > div {
width: 60px;
height: 60px;
background-color: green;
border: 2px solid black;
margin: 10px;
}
.inner-spacing tr:first-child > td > div {
margin-top: 0px;
}
.inner-spacing tr:last-child > td > div {
margin-bottom: 0px;
}
.inner-spacing tr > td:first-child > div {
margin-left: 0px;
}
.inner-spacing tr > td:last-child > div {
margin-right: 0px;
}
<table class="inner-spacing">
<tr>
<td>
<div/>
</td>
<td>
<div/>
</td>
</tr>
<tr>
<td>
<div/>
</td>
<td>
<div/>
</td>
</tr>
</table>
So to summarize, I would like the table to have border spacing with the table border collapsing onto the cells (no spacing).
I wonder if there are some other solutions - so any new solution is welcome!
This will be tricky a little bit...you will need to set display:block and border-spacing:10px for spacing between cells and same negative margin:-10px to remove the outer spacing
Stack Snippet
table {
font: bold 13px Verdana;
background: black;
margin: 30px auto;
border-spacing: 0;
}
table td {
padding: 30px;
background: red;
color: #fff;
}
table tbody {
margin: -10px;
display: block;
border-spacing: 10px;
}
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
This is kinda tricky, you need to follow something like this:
table, td {border: 1px solid #999; border-collapse: collapse;}
table {margin: -5px;}
table td {width: 32px; height: 32px; margin: 5px;}
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>

What is the value in CSS for border when using tables?

What is the value in CSS for border when using tables? For example:
This is my desired look.
<table border=4px >
<tr>
<th>1</th>
<th>1</th>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
</table>
but I want to do it with CSS only. So I tried inline like so
<table style="
border-width: 4px;
border-spacing: 3px;
border-style: outset;
border-color: gray;
border-collapse: separate;
background-color: white;
border-width: 2px;
padding: 1px;
border-style: inset;
border-color: gray;
background-color: white;
border-width: 2px;
" >
<tr>
<th>1</th>
<th>1</th>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
</table>
When I do this the cell borders are gone (at least in Firefox). I tried using the wizard from here http://www.somacon.com/p141.php but it does not help. No matter what I do I can not get these "inner walls" to appear without using "table border=1px"?
first thing i would suggest, is have a look Here
now after you learnt basic css and how to use styles, to apply "inner" borders to a table, you basically apply the borders to the cells themselves:
table tr th,
table tr td{
border:1px solid black;
}
or separately:
table tr th,
table tr td{
border-style: solid;
border-width: 1px;
border-color: black;
}
and then, to get rid of the cell spacing you apply this to the table itself:
table{
border-collapse: collapse;
}
EXAMPLE
You can add a separate style tag elsewhere:
<style type="text/css">
table tr td {
border: 4px gray solid;
}
table tr th {
border: 4px gray solid;
}
</style>

HTML: How to add a delete link inside a html table, but still visible as outside the table

I have a table in html with some tabular data.
The thing is that I have designed a delete and edit visually link outside the table (on the left side of the table), that will only be visible when the user hovers the table row.
How can I add these links without messing up the default table layout?
The current problem is that I need to create a holding the delete and edit link, and this messes up the table structure when they are not visible.
So, is there a way to add a container to a table (needs to follow the table row structure) that is not a td? Or do you know about some examples doing something similar that I could have a look at?
Thanks
It got a little complicated, but there's a demo at JS Bin to demonstrate my approach. I'm not entirely sure that -webkit-border-radius supports the notation that I used (I tested in Chrome which supports border-radius), so it might be worth checking.
Incidentally, because of the approach I took (mainly to avoid having to manually add classes) to what could be a 'clean' design, there are some near-bleeding-edge CSS selectors, such as tbody tr:nth-child(odd) td:first-child. I think all of this but the :nth-child(odd) pseudo-selector should be understood by IE7+ (with a valid doctype), but I don't have an installation of Windows on which to test my assumption. As this particular rule is only there to overrule the specificity of the earlier selector to add zebra-striping, if neither are understood nothing is broken, it's just a slightly less jazzy table is all.
The CSS is below:
body
{
background-color: #39f;
}
thead tr th,
tbody tr td
{
background-color: #fff;
border-collapse: collapse;
color: #000;
height: 2em;
margin: 0;
padding: 0.5em;
vertical-align: center;
width: auto;
}
tbody tr:nth-child(odd) td
{
background-color: #ffa;
}
th
{
font-weight: bold;
}
tr th:first-child,
tr td:first-child,
tbody tr:nth-child(odd) td:first-child
{
background-color: transparent;
border-radius: 1em 0 0 1em;
color: transparent;
moz-border-radius: 1em 0 0 1em;
padding: 0.5em 0 0.5em 0.5em;
webkit-border-radius: 1em 0 0 1em;
}
tr:hover td:first-child,
tbody tr:nth-child(odd):hover td:first-child
{
background-color: #fff;
color: #000;
}
tbody tr:nth-child(odd):hover td:first-child
{
background-color: #ffa;
color: #000;
}
And the html:
<table cellspacing="0">
<thead>
<tr>
<th></th>
<th>visible</th>
<th>visible</th>
<th>visible</th>
<th>visible</th>
</tr>
</thead>
<tbody>
<tr>
<td>X</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
</tr>
<tr>
<td>X</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
</tr>
<tr>
<td>X</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
</tr>
</tbody>
</table>
Edited
I've added a side-by-side comparison of the above demonstration and an additional approach, which I think might, in the presence of a valid standards-mode doctype, work reasonably well in older browsers.
The revised demo is here: JS Bin, and can, of course, be edited by clicking on the 'Edit using JS Bin' button.
The relevant CSS can also be seen by hovering over the tables (though it probably works better with larger displays).
Edited
To add in the all finished version, to the best -I think- of my ability, there's two tables (as can be seen at JS Bin (each using slightly different mark-up, and quite different css) to demonstrate at least two ways this can be achieved.
Both tables share this CSS:
body {
background-color: #39f;
}
th {
font-weight: bold;
border-bottom: 2px solid #000;
}
th.title {
border-bottom: 1px solid #000;
}
th.hidden {
border: 0 none transparent;
}
thead tr th,
tbody tr td {
width: auto;
height: 2em;
vertical-align: center;
background-color: #fff;
color: #000;
padding: 0.5em;
margin: 0;
border-collapse: collapse;
}
Next is the 'up-to-date' browsers' CSS:
#preferred thead tr th:first-child {
border: 0 none transparent;
}
#preferred tbody tr:nth-child(odd) td {
background-color: #ffa;
}
#preferred tr th:first-child,
#preferred tr td:first-child,
#preferred tbody tr:nth-child(odd) td:first-child {
color: transparent;
background-color: transparent;
padding: 0.5em 0 0.5em 0.5em;
-webkit-border-top-left-radius: 1em;
-webkit-border-bottom-left-radius: 1em;
-moz-border-radius: 1em 0 0 1em;
border-radius: 1em 0 0 1em;
}
#preferred tr:hover td:first-child,
#preferred tbody tr:nth-child(odd):hover td:first-child {
color: #000;
background-color: #fff;
}
#preferred tbody tr:nth-child(odd):hover td:first-child {
color: #000;
background-color: #ffa;
}
And the relevant html mark-up:
<table cellspacing="0" id="preferred">
<thead>
<tr>
<th></th>
<th class="title" colspan="4">id="preferred"</th>
</tr>
<tr>
<th></th>
<th>visible</th>
<th>visible</th>
<th>visible</th>
<th>visible</th>
</tr>
</thead>
<tbody>
<tr>
<td>X</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
</tr>
<tr>
<td>X</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
</tr>
<tr>
<td>X</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
</tr>
</tbody>
</table>
Next is the older browser's CSS:
#ieMaybe {
background-color: #39f;
}
#ieMaybe th,
#ieMaybe td {
background-color: #fff;
}
#ieMaybe th.hidden,
#ieMaybe td.hidden {
color: #39f;
background-color: transparent;
padding: 0.5em 0 0.5em 0.5em;
-webkit-border-top-left-radius: 1em;
-webkit-border-bottom-left-radius: 1em;
-moz-border-radius: 1em 0 0 1em;
border-radius: 1em 0 0 1em;
}
#ieMaybe tr:hover td.hidden,
#ieMaybe tr td.hidden:hover {
color: #000;
background-color: #fff;
}
And the older browsers' html mark-up:
<table cellspacing="0" id="ieMaybe">
<thead>
<tr>
<th class="hidden"></th>
<th class="title" colspan="4">id="ieMaybe"</th>
</tr>
<tr>
<th class="hidden"></th>
<th>visible</th>
<th>visible</th>
<th>visible</th>
<th>visible</th>
</tr>
</thead>
<tbody>
<tr>
<td class="hidden">X</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
</tr>
<tr>
<td class="hidden">X</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
</tr>
<tr>
<td class="hidden">X</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
<td>visible</td>
</tr>
</tbody>
</table>
I can't say, for sure, what versions of IE < 8 do in the presence of such chicanery, but IE8 (with a <!DOCTYPE html>) renders it willingly, albeit with no pretence at curved borders. Which is a shame, here's waiting for IE9! =)
As #Yi Jiang noted, in the comments, there were a couple of errors in the first-posted code, those have been left as is (because I'm starting to go CSS-blind), but the code-blocks above have been directly pasted from the latest working JS Bin demo, so unless ctrl+V's been playing up, it should, I hope, be fine.
your could add the links in the first cell and hide them with CSS. position them absolutely and move them to appear as if they are partially outside the table.
you could put all the controls inside a column that has a class "controls" and then play with the css to hide or show... something like this
example
hope this helps