I have html tables and I would like to add summary columns next to it.
I could create simple table, but I couldn't figure out how to set separate tables next to it.
My desired result is described below. If someone has idea, please let me know.
td {
border: solid 1px black;
padding:5px;
}
table {
border-collapse: collapse;
}
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
Here you go with a solution
td {
border: solid 1px black;
padding:5px;
}
table {
border-collapse: collapse;
}
.noborder {
border: none;
padding: 5px 8px;
}
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td class="noborder"></td>
<td>2</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
<td class="noborder"></td>
<td>2</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
<td class="noborder"></td>
<td>2</td>
</tr>
</table>
Rather than creating another table I will suggest to use the no-border cell.
Hope this will help you
According to your requirement, you actually do not need another table, but in future if you want to use table side by side then you can use below solution.
td {
border: solid 1px black;
padding:5px;
}
table {
border-collapse: collapse;
float:left;
}
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
<table style="margin-left:20px">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
Related
I tried to create html tables with header.
I added 2 rows but I couldn't figure out how to align to header.
My desired result is like this.
below is my previous work.
What is wrong point? how can I fix it? if someone has opinion please let me know.
Thanks
td {
padding:5px;
border:solid black 1px;}
table{
border-collapse:collapse;
border:solid black 1px;}
<table>
<tr>
<th>header</th>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
I hope this will help you:
td {
padding:5px;
border:solid black 1px;}
table{
border-collapse:collapse;
border:solid black 1px;}
<table>
<tr>
<th rowspan="2">header</th>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
You have to use rowspan="2" since you want to merge 2 rows.
td {
padding: 5px;
border: solid black 1px;
}
table {
border-collapse: collapse;
border: solid black 1px;
}
<table>
<tr>
<th rowspan="2">header</th>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
</tr>
</table>
Please find attached the solution:
<table>
<tr>
<td rowspan="2"> Header</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
I got what I want as per the screenshot. However, the borders got attached to one another and got thicker. How do I maintain the border size?
This is actually what I'm planning to make it look like:
DEMO: https://jsfiddle.net/xnqh9d70/
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>Day</td>
<td>Sun.</td>
<td>Mon.</td>
<td>Tues.</td>
<td>Wed.</td>
<td>Thu.</td>
<td>Fri.</td>
<td>Sat.</td>
<td></td>
</tr>
<tr>
<td>Fare(s)</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td></td>
</tr>
<tr>
<td>Date(s)</td>
<td>9</td>
<td>8</td>
<td>7</td>
<td>6</td>
<td>5</td>
<td>4</td>
<td>3</td>
<td>2</td>
</tr>
</tbody>
</table>
CSS:
table {
border-collapse: separate;
empty-cells: hide;
border: 0;
border-color: #000000;
}
This is probably not the nicest solution, but what you can do is eliminate one of the two borders completely, only having borders on elements where it is needed then.
table {
border-collapse: separate;
empty-cells: hide;
border: 0;
border-color: #000000;
border-left: 1px solid black
}
tr {
border-bottom: none;
}
td {
border-left: none;
}
tr:last-of-type {
border-bottom: 1px solid black;
}
td:first-of-type {
border-right: 1px solid black;
}
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>Day</td>
<td>Sun.</td>
<td>Mon.</td>
<td>Tues.</td>
<td>Wed.</td>
<td>Thu.</td>
<td>Fri.</td>
<td>Sat.</td>
<td></td>
</tr>
<tr>
<td>Fare(s)</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td></td>
</tr>
<tr>
<td>Date(s)</td>
<td>9</td>
<td>8</td>
<td>7</td>
<td>6</td>
<td>5</td>
<td>4</td>
<td>3</td>
<td>2</td>
</tr>
</tbody>
</table>
The general way for creating borders between cells is by styling the td elements, and setting border-collapse: collapse; on the table.
I also added a class for your blank cells to remove the border on them.
table {
empty-cells: hide;
border-collapse: collapse;
border-color: #000000;
}
td {
border: 1px solid black;
}
.empty-cell {
border: none;
}
<table>
<tbody>
<tr>
<td>Day</td>
<td>Sun.</td>
<td>Mon.</td>
<td>Tues.</td>
<td>Wed.</td>
<td>Thu.</td>
<td>Fri.</td>
<td>Sat.</td>
<td class="empty-cell"></td>
</tr>
<tr>
<td>Fare(s)</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td class="empty-cell"></td>
</tr>
<tr>
<td>Date(s)</td>
<td>9</td>
<td>8</td>
<td>7</td>
<td>6</td>
<td>5</td>
<td>4</td>
<td>3</td>
<td>2</td>
</tr>
</tbody>
</table>
empty-cells: hide; is use to hide border
The empty-cells property sets whether or not to display borders on
empty cells in a table. Reference Here
you can apply css to td:empty for hide empty td
and for border-collapse: separate; case you need to add manually border-right to last td
table {
border-collapse: collapse;
border-color: #000000;
empty-cells: hide;
}
td {
border: 1px solid black;
}
td:empty {
border: 0px;
}
<table>
<tbody>
<tr>
<td>Day</td>
<td>Sun.</td>
<td>Mon.</td>
<td>Tues.</td>
<td>Wed.</td>
<td>Thu.</td>
<td>Fri.</td>
<td>Sat.</td>
<td></td>
</tr>
<tr>
<td>Fare(s)</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td></td>
</tr>
<tr>
<td>Date(s)</td>
<td>9</td>
<td>8</td>
<td>7</td>
<td>6</td>
<td>5</td>
<td>4</td>
<td>3</td>
<td>2</td>
</tr>
</tbody>
</table>
I have a table and I want to make the first row different background color for instance blue. I use table tr:first-child but it doesn't work. Can you help me? Thanks.
<table>
<tr><td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr><td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr><td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
You can use tr:first-of-type. check updated snippet below.
table tr:first-of-type td {
background: blue;
}
<table>
<tr><td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr><td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr><td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
you can use this:
table tr:first-child {
background: blue;
}
or you can add class to your first tr
.bg-blue {
background:blue;
}
<table>
<tr class="bg-blue">
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>
You can use this snippet.
table tr:first-child td {
background: blue;
}
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
Hope this helps :)
As you are saying the first-child is not working, I suggest you check it's parent property if it has any property which is overriding your first-child property. Basically, it should work that way. Also, I would like to know which browser actually you are seeing the issue.
Try this:
table tr:first-child {
background:blue;
color:white;
}
<table>
<tr><td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr><td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr><td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
You can add a comment with your issue if still it is not resolved with the solution.
How can I make border 1px for table td. I have a table and I want to make the border 1px. Thank you!
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
You can use like this
table { border-collapse: collapse;}
for table.
And give
td {
border: 1px solid red;
}
You can use border-collapse for table with css.
Try This:
td {
border: 1px solid #000;
}
td {
border: 1px solid #000;
}
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
Or
table {
border-collapse: collapse;
}
td {
border: 1px solid #000;
}
table {
border-collapse: collapse;
}
td {
border: 1px solid #000;
}
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
You can define a CSS style for td.
This will affect all tables in HTML page.
<style>
td {
border:1px solid black
}
</style>
<table >
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
Try like this :
table {
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
}
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
This table:
<table border="1">
<tbody><tr>
<td></td>
<td>Grokkability</td>
<td>PIA Factor*</td>
<td>FancyPantsiness</td>
</tr>
<tr>
<td>XML</td>
<td>10</td>
<td>8</td>
<td>2</td>
</tr>
<tr>
<td>Code</td>
<td>10</td>
<td>5</td>
<td>4</td>
</tr>
<tr>
<td>Auto-Wiring</td>
<td>2</td>
<td>2</td>
<td>10</td>
</tr>
</tbody></table>
...looks as I want it to on jsfiddle (http://jsfiddle.net/clayshannon/9AX8H/), but on Code Project it has lost its cell formatting (http://www.codeproject.com/Tips/711127/Swapping-Out-Concrete-Implementations-of-Interface)
What must I do to force the cell boundaries to be visible?
You probably want to use css..
<table class="border">
<tbody><tr>
<th></th>
<th>Grokkability</th>
<th>PIA Factor*</th>
<th>FancyPantsiness</th>
</tr>
<tr>
<th>XML</th>
<td>10</td>
<td>8</td>
<td>2</td>
</tr>
<tr>
<th>Code</th>
<td>10</td>
<td>5</td>
<td>4</td>
</tr>
<tr>
<th>Auto-Wiring</th>
<td>2</td>
<td>2</td>
<td>10</td>
</tr>
</tbody></table>
Your css
.border {
border: solid 1pt;
border-collapse:collapse;
}
.border th{
border: 1px solid #000000;
padding: 4px;
background-color: #34B767;
}
.border td{
border: 1px solid;
padding: 4px;
}