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>
Related
I encountered strange problem with table styling. Everything at least for me in code seems to be fine. however effects are unexpected.
I have to leave 0.3em margin as this is my student task, but I don't want the lines in the bottom to be separate.
Any webmaster can help? I would be very thankful. Here is peace of my code:
<table>
<tr>
<td>Kategoriasystematyczna</td>
<td>Takson</td>
</tr>
<tr>
<td>Domena</td>
<td>eukarionty</td>
</tr>
<tr>
<td>Królestwo</td>
<td>zwierzęta</td>
</tr>
<tr>
<td>Gromada</td>
<td>ssaki</td>
</tr>
<tr>
<td>Podgromada</td>
<td>ssakiżyworodne
<td>
</tr>
<tr>
<td>Infragromada</td>
<td>łożyskowce
<td>
</tr>
<tr>
<td>Rząd</td>
<td>parzystokopytne
<td>
</tr>
<tr>
<td>Rodzina</td>
<td>żyrafowate
<td>
</tr>
<tr>
<td>Rodzaj</td>
<td>Giraffa(Brünnich,1771)
<td>
</tr>
<tr>
<td>Gatunek</td>
<td>żyrafa
<td>
</tr>
</table>
and style
td{
border:1pxsolidblue;
margin:0.3em,0.3em,0.3em,0.3em;
}
table{
border:1pxsolidblue;
border-collapse:collapse;
}
And this is how my table looks like
Anyone? Antyhing?
you have opening tags instead of closing tags td:
change
<td>Gatunek</td>
<td>żyrafa
<td>
to
<td>Gatunek</td>
<td>żyrafa
</td>
in various places
As mentioned in my original comment to your answer (prior to deletion for redundancy), the problem is the syntax errors of unclosed <td> elements (possibly typos), correcting your HTML fixes the problem. Corrected HTML:
<table>
<tr>
<td>Kategoriasystematyczna</td>
<td>Takson</td>
</tr>
<tr>
<td>Domena</td>
<td>eukarionty</td>
</tr>
<tr>
<td>Królestwo</td>
<td>zwierzęta</td>
</tr>
<tr>
<td>Gromada</td>
<td>ssaki</td>
</tr>
<tr>
<td>Podgromada</td>
<td>ssakiżyworodne</td>
</tr>
<tr>
<td>Infragromada</td>
<td>łożyskowce</td>
</tr>
<tr>
<td>Rząd</td>
<td>parzystokopytne</td>
</tr>
<tr>
<td>Rodzina</td>
<td>żyrafowate</td>
</tr>
<tr>
<td>Rodzaj</td>
<td>Giraffa(Brünnich,1771)</td>
</tr>
<tr>
<td>Gatunek</td>
<td>żyrafa</td>
</tr>
</table>
JS Fiddle demo.
Also, your CSS is problematic, you have commas between the values of your margin property-values and no spaces to separate the properties of the border; fixed, it should look like:
td {
border: 1px solid blue;
margin: 0.3em;
}
table {
border: 1px solid blue;
border-collapse: collapse;
}
This is a table that I would like to achieve:
But I keep getting something like this:
This is what I've tried:
<table>
<tr>
<td rowspan="2">a</td>
<td colspan="2">b</td>
</tr>
<tr>
<td colspan="2">c</td>
</tr>
<tr>
<td colspan="2">d</td>
<td>e</td>
</tr>
</table>
Here's a link to JSFiddle with this (with some extra code for illustration): http://jsfiddle.net/2292D/
You need only vertical-align:middle and text-align:center
Apply this css to div
div {
display:table-cell; // Change
vertical-align:middle; //Change
border: 1px solid blue;
}
td {
border: 1px solid red;
text-align:center; // Change
}
Fiddle Demo
Good old days using table, use rowspan and colspan to achieve that kind of tablular structure, if you are using this for layout than don't, use div instead with float and CSS Positioning.
Demo
<table border="1" width="100%">
<tr>
<td rowspan="2" width="30%">a</td>
<td colspan="2">b</td>
</tr>
<tr>
<td colspan="2">c</td>
</tr>
<tr>
<td colspan="2" width="70%">d</td>
<td>e</td>
</tr>
</table>
I guess you need 3 rows for that, try my code:
<table>
<tr>
<td rowspan="2"><div id="a">a</div></td>
<td colspan="2"><div id="b">b</div></td>
</tr>
<tr>
<td colspan="2"><div id="c">c</div></td>
</tr>
<tr>
<td colspan="2"><div id="d">d</div></td>
<td><div id="e">e</div></td>
</tr>
Here's my fiddle: http://jsfiddle.net/LLe5c/
apply your id on td
html:
<table>
<tr>
<td id="a" rowspan="2"><div>a</div></td>
<td id="b" colspan="2"><div >b</div></td>
</tr>
<tr>
<td id="c" colspan="2"><div >c</div></td>
</tr>
<tr>
<td id="d" colspan="2"><div >d</div></td>
<td id="e"><div >e</div></td>
</tr>
</table>
Here is the Solution
<table>
<tr>
<td rowspan="2">a</td>
<td colspan="2">b</td>
</tr>
<tr>
<td colspan="2">c</td>
</tr>
<tr>
<td colspan="2">d</td>
<td>e</td>
</tr>
</table>
<style>
table {
border-collapse: collapse;
border-spacing: 0;
}
td {
border: 1px solid red;
}
</style>
html
<table border="1">
<tr>
<td>one</td>
<td>two</td>
</tr>
<tr>
<td>one</td>
<td>two</td>
</tr>
</table>
This will output borders like this
+---+---+
| | |
+---+---+
| | |
+---+---+
But I would like to display the border in table only not to td like this
+--------+
| |
| |
| |
+--------+
How can I do just with html markup. (NO CSS / NO INLINE STYLES)
In some cases I need to remove some td borders only and some td border to display something like this:
+---+---+
| | |
+---+ |
| | |
+---+---+
simple solution from my end is to keep another Table with border and insert your table in the outer table.
<table border="1">
<tr>
<td>
<table border="0">
<tr>
<td>one</td>
<td>two</td>
</tr>
<tr>
<td>one</td>
<td>two</td>
</tr>
</table>
</td>
</tr>
</table>
To remove borders between cells, while retaining the border around the table, add the attribute rules=none to the table tag.
There is no way in HTML to achieve the rendering specified in the last figure of the question. There are various tricky workarounds that are based on using some other markup structure.
First
<table border="1">
<tr>
<td style='border:none;'>one</td>
<td style='border:none;'>two</td>
</tr>
<tr>
<td style='border:none;'>one</td>
<td style='border:none;'>two</td>
</tr>
</table>
Second example
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td style='border-left:none;border-top:none'>one</td>
<td style='border:none;'>two</td>
</tr>
<tr>
<td style='border-left:none;border-bottom:none;border-top:none'>one</td>
<td style='border:none;'>two</td>
</tr>
</table>
<table border="1">
<tr>
<td>one</td>
<td style="border-bottom-style: hidden;">two</td>
</tr>
<tr>
<td>one</td>
<td style="border-top-style: hidden;">two</td>
</tr>
</table>
Surround it with a div and give it a border and remove the border from the table
<div style="border: 1px solid black">
<table border="0">
<tr>
<td>one</td>
<td>two</td>
</tr>
<tr>
<td>one</td>
<td>two</td>
</tr>
</table>
</div>
You can check the working fiddle here
As per your updated question .... where you want to add or remove borders.
You should remove borders from the html table first and then do the following
<td style="border-top: 1px solid black">
Assuming like you only want the top border. Similarly you have to do for others. Better way create four css class...
.topBorderOnly {
border-top: 1px solid black;
}
.bottomBorderOnly {
border-bottom: 1px solid black;
}
Then add the css to your code depending on the requirements.
<td class="topBorderOnly bottomBorderOnly">
This will add both top and bottom border, similarly do for the rest.
Try:
<table border="1">
<tr>
<td>
<table border="">
...
</table>
</td>
</tr>
</table>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td>
<table border="0">
<tr>
<td>one</td>
<td>two</td>
</tr>
<tr>
<td>one</td>
</tr>
</table>
</td>
</tr>
</table>
The rules="none" worked perfectly for me just now. I can't seem to get borders back around specific cells no matter what I try. I'm new though, been teaching myself with certificate courses and YouTube tutorials. I'm writing my first HTML CSS webpage. I plan to put images in the cells so I can add a border around those no problem. Just wanted to share in case someone else gets stumped by trying to get borders back on specific cells.
I don't know how to merge rows and columns inside HTML tables.
Can you please help me with making such a table in HTML?
If you're confused how table layouts work, they basically start at x=0, y=0 and work their way across. Let's explain with graphics, because they're so much fun!
When you start a table, you make a grid. Your first row and cell will be in the top left corner. Think of it like an array pointer, moving to the right with each incremented value of x, and moving down with each incremented value of y.
For your first row, you're only defining two cells. One spans 2 rows down and one spans 4 columns across. So when you reach the end of your first row, it looks something like this:
<table>
<tr>
<td rowspan="2"></td>
<td colspan="4"></td>
</tr>
</table>
Now that the row has ended, the "array pointer" jumps down to the next row. Since x position 0 is already taken up by a previous cell, x jumps to position 1 to start filling in cells. * See note about difference between rowspans.
This row has four cells in it which are all 1x1 blocks, filling in the same width of the row above it.
<table>
<tr>
<td rowspan="2"></td>
<td colspan="4"></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
The next row is all 1x1 cells. But, for example, what if you added an extra cell? Well, it would just pop off the edge to the right.
<table>
<tr>
<td rowspan="2"></td>
<td colspan="4"></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
* But what if we instead (rather than adding the extra cell) made all these cells have a rowspan of 2? The thing you need to consider here is that even though you're not going to be adding any more cells in the next row, the row still must exist (even though it's an empty row). If you did try to add new cells in the row immediately after, you'd notice that it would start adding them to the end of the bottom row.
<table>
<tr>
<td rowspan="2"></td>
<td colspan="4"></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td rowspan="2"></td>
<td rowspan="2"></td>
<td rowspan="2"></td>
<td rowspan="2"></td>
<td rowspan="2"></td>
</tr>
<tr>
<td></td>
</tr>
</table>
Enjoy the wonderful world of creating tables!
I'd suggest:
table {
empty-cells: show;
border: 1px solid #000;
}
table td,
table th {
min-width: 2em;
min-height: 2em;
border: 1px solid #000;
}
<table>
<thead>
<tr>
<th rowspan="2"></th>
<th colspan="4"> </th>
</tr>
<tr>
<th>I</th>
<th>II</th>
<th>III</th>
<th>IIII</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>
References:
td element.
th element.
tbody element.
thead element.
table element.
If anyone is looking for a rowspan on both the left AND on the right,
here is how you can do it:
table {
border-collapse: collapse;
}
td {
padding: 20px;
border: 1px solid black;
text-align: center;
}
<table>
<tbody>
<tr>
<td rowspan="2">LEFT</td>
<td> 1 </td>
<td> 2 </td>
<td> 3 </td>
<td> 4 </td>
<td rowspan="2">RIGHT</td>
</tr>
<tr>
<td> 5 </td>
<td> 6 </td>
<td> 7 </td>
<td> 8 </td>
</tr>
<tr>
<td> - </td>
<td> - </td>
<td> - </td>
<td> - </td>
<td> - </td>
<td> - </td>
</tr>
</tbody>
</table>
Alternatively, if you want to add the LEFT and RIGHT to an existing rowset, you can achieve the same result by throwing them in with a collapsed colspan in between:
table {
border-collapse: collapse;
}
td {
padding: 20px;
border: 1px solid black;
text-align: center;
}
<table>
<tbody>
<tr>
<td rowspan="3">LEFT</td>
<td colspan="4" style="padding: 0; border-bottom: solid 1px transparent;"></td>
<td rowspan="3">RIGHT</td>
</tr>
<tr>
<td> 1 </td>
<td> 2 </td>
<td> 3 </td>
<td> 4 </td>
</tr>
<tr>
<td> 5 </td>
<td> 6 </td>
<td> 7 </td>
<td> 8 </td>
</tr>
<tr>
<td> - </td>
<td> - </td>
<td> - </td>
<td> - </td>
<td> - </td>
<td> - </td>
</tr>
</tbody>
</table>
Use rowspan if you want to extend cells down and colspan to extend across.
You can use rowspan="n" on a td element to make it span n rows, and colspan="m" on a td element to make it span m columns.
Looks like your first td needs a rowspan="2" and the next td needs a colspan="4".
The property you are looking for that first td is rowspan:
http://www.angelfire.com/fl5/html-tutorial/tables/tr_code.htm
<table>
<tr><td rowspan="2"></td><td colspan='4'></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td></tr>
</table>
<style type="text/css">
table { border:2px black dotted; margin: auto; width: 100%; }
tr { border: 2px red dashed; }
td { border: 1px green solid; }
</style>
<table>
<tr>
<td rowspan="2">x</td>
<td colspan="4">y</td>
</tr>
<tr>
<td>I</td>
<td>II</td>
<td>III</td>
<td>IV</td>
</tr>
<tr>
<td>nothing</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</table>
I have used ngIf for one of my similar logic. it is as follows:
<table>
<tr *ngFor="let object of objectData; let i= index;">
<td *ngIf="(i%(object.rowSpan))==0" [attr.rowspan]="object.rowSpan">{{object.value}}</td>
</tr>
</table>
here,
i'm getting rowspan value from my model object.
<body>
<table>
<tr><td colspan="2" rowspan="2">1</td><td colspan="4">2</td></tr>
<tr><td>3</td><td>3</td><td>3</td><td>3</td></tr>
<tr><td colspan="2">1</td><td>3</td><td>3</td><td>3</td><td>3</td></tr>
</table>
</body>
Colspan and Rowspan
A table is divided into rows and each row is divided into cells. In some situations we need the Table Cells span across (or merged) more than one column or row. In these situations we can use Colspan or Rowspan attributes.
Colspan
The colspan attribute defines the number of columns a cell should span (or merge) horizontally. That is, you want to merge two or more Cells in a row into a single Cell.
<td colspan=2 >
How to colspan ?
<html>
<body >
<table border=1 >
<tr>
<td colspan=2 >
Merged
</td>
</tr>
<tr>
<td>
Third Cell
</td>
<td>
Forth Cell
</td>
</tr>
</table>
</body>
</html>
Rowspan
The rowspan attribute specifies the number of rows a cell should span vertically. That is , you want to merge two or more Cells in the same column as a single Cell vertically.
<td rowspan=2 >
How to Rowspan ?
<html>
<body >
<table border=1 >
<tr>
<td>
First Cell
</td>
<td rowspan=2 >
Merged
</td>
</tr>
<tr>
<td valign=middle>
Third Cell
</td>
</tr>
</table>
</body>
</html>
It is similar to your table
<table border=1 width=50%>
<tr>
<td rowspan="2">x</td>
<td colspan="4">y</td>
</tr>
<tr>
<td bgcolor=#FFFF00 >I</td>
<td>II</td>
<td bgcolor=#FFFF00>III</td>
<td>IV</td>
</tr>
<tr>
<td>empty</td>
<td bgcolor=#FFFF00>1</td>
<td>2</td>
<td bgcolor=#FFFF00>3</td>
<td>4</td>
</tr>
I am wondering whether it is possible to have a fixed table layout and have one column in the middle with a wider width than all the others...?
I'd appreciate any help! :)
Thanks,
Piotr.
Just add the style=\"width: 20%;\" to the th (or td) tag of that column. Check [1]:
<table style="table-layout:fixed; border: 1px solid black; ">
<tr>
<th style="width:30% ">name</th>
<th style="width:70% ">Color</th>
</tr>
<tr>
<td>N1</td>
<td>red</td>
</tr>
<tr>
<td>N2</td>
<td>blue</td>
</tr>
</table>
[1] http://jsfiddle.net/AP5rL/1/
Just set the width attribute on the TD tag corresponding to the wider column.
Example:
<table width="650">
<tr>
<td width="100">normal</td>
<td width="100">normal</td>
<td width="250">wide</td>
<td width="100">normal</td>
<td width="100">normal</td>
</tr>
</table>
Can you add a class to the column that needs a different width? If so, you can use the class to manipulate width:
HTML
<table width="650">
<tr>
<td>normal</td>
<td>normal</td>
<td class="wider">wide</td>
<td>normal</td>
<td>normal</td>
</tr>
</table>
CSS
td.wider {
width: 250px;
}