I have a table like so:
<table class="data">
<thead>
<tr class="columns">
<th>
</th>
<th>
<h2>Title</h2>
</th>
<th>
<h2>Location</h2>
</th>
<th>
<h2>Download</h2>
</th>
<th>
<h2>Analytics</h2>
</th>
<th>
<h2>Uploaded</h2>
</th>
<th>
<h2>Updated</h2>
</th>
</tr>
<thead>
<tbody>
<form>
<tr class="row">
<td><input type="checkbox" name="ID" value="1" /></td>
<td>Some Title</td>
<td>Some Url</td>
<td>Some Url</td>
<td>view Analytics</td>
<td>Some person</td>
<td>Some info</td>
</tr>
<tr class="row">
<td><input type="checkbox" name="ID" value="2" /></td>
<td>Some Title</td>
<td>Some Url</td>
<td>Some Url</td>
<td>view Analytics</td>
<td>Some person</td>
<td>Some info</td>
</tr>
</form>
<tbody>
</table>
I want to insert another tr containing tds at the bottom of the table (just after the </form> tag), however I do not want their width to be effected by or effect the other tds above them.
The table has no set widths and sizes to it's content.
How would I go about this?
Add another table in the last cell:
<tr>
<td colspan="6">
<table>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</td>
</tr>
You can not do that unless you add your <tr>, combine all <td>-s into one (colspan) in it and put a nested table inside that <td> - in that new table you can set your <td>-s width
See colspan and rowspan attributes. To be perfectly flexible you should make another table under the above table. Make the above table style="margin:0;" and the below table have something like style="margin:0;position:relative;top:-2" to make it seem like they're connected. This would be tricky to make it look the same cross browser though.
Related
I need to design a HTML table as the attachment below but I seem to be struggling due to my lack of understanding in HTML table.
This is what I've come up with so far but as you can see, it's not even close to the end result. I hope that someone can point me in the right direction.
<section class="mb-5">
<div class="container">
<div class="row">
<div class="col-12">
<!-- Heading -->
<h2 class="mb-3">
Task activities reports
</h2>
<div class="table-responsive border">
<table class="table mb-0">
<thead>
<tr>
<th scope="col">Service</th>
<th scope="col">Category</th>
<th scope="col">
<table>
<thead>
<tr>
<th colspan="10">Percent completed</th>
</tr>
<tr>
<th>10%</th>
<th>20%</th>
<th>30%</th>
<th>40%</th>
<th>50%</th>
<th>60%</th>
<th>70%</th>
<th>80%</th>
<th>90%</th>
<th>100%</th>
</tr>
</thead>
</table>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>Clipping path</td>
<td>Category 1</td>
<td>
<table>
<tbody>
<tr>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>2</td>
<td>3</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>1</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
You need to use the colspan and rowspan attributes, not nested tables. colspan tells a cell to span the width of two columns, and rowspan tells it to span the height of two rows.
I've rendered your header rows and the first three rows of content based on what I said here. The rest of the table content follows the same principles.
table {
border-collapse: collapse;
}
td,
th {
border: 1px solid black;
}
<table>
<thead>
<tr>
<th rowspan="2">Service</th>
<th rowspan="2">Category</th>
<th colspan="11">Percent completed</th>
</tr>
<tr>
<th>10%</th>
<th>20%</th>
<th>30%</th>
<th>40%</th>
<th>50%</th>
<th>60%</th>
<th>70%</th>
<th>80%</th>
<th>90%</th>
<th>100%</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="6">Clipping Path</td>
<td>Category 1</td>
<td></td>
<td>3</td>
<td></td>
<td></td>
<td>2</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>1000</td>
<td>1005</td>
</tr>
<tr>
<td>Category 2</td>
<td>2</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>3</td>
<td></td>
<td></td>
<td></td>
<td>1100</td>
<td>1105</td>
</tr>
<tr>
<td>Category 3</td>
<td></td>
<td></td>
<td></td>
<td>5</td>
<td></td>
<td></td>
<td>4</td>
<td></td>
<td></td>
<td>1200</td>
<td>1209</td>
</tr>
</tbody>
</table>
I've added CSS for borders so you can see the edges of the cells.
It's a little hard to get used to at first, because you have to ignore the presence of the cells in the rows where they "grow" to from where they were declared. Thus I've applied rowspan="2" to the Service heading, and that cell "grows" into the next row, along with Category. So that 10% heading shows up below Percent (since it only spans 1 row) because Service and Category are taking up space in the row though never declared in the <tr>.
How can I get "Change username", "Change password", and "delete user" to be positioned inline and get them under the "Actions" category?
<table>
<thead>
<tr>
<th>Username</th>
<th>Listings</th>
<th>Actions</th>
<tr>
</thead>
<tbody>
<tr>
<td>hi</td>
<td>hi</td>
</tr>
<tr>
<td>hi</td>
<td>hi</td>
</tr>
<tr>
<td>
<a>ChangeUsername</a>
<a>ChangePassword</a>
<form>
<button>Delete User</button>
</form>
</td>
</tr>
</tbody>
</table>
inside tbody a <tr> should have 3 <td> like on thead
<table border="1">
<thead>
<tr>
<th>Username</th>
<th>Listings</th>
<th>Actions</th>
<tr>
</thead>
<tbody>
<tr>
<td>hi</td>
<td>ha</td>
<td>
<button>ChangeUsername</button>
<button>ChangePassword</button>
<button>Delete User</button>
</td>
</tr>
<tr>
<td>hi</td>
<td>hi</td>
<td>
<button>ChangeUsername</button>
<button>ChangePassword</button>
<button>Delete User</button>
</td>
</tr>
</tbody>
</table>
You need to put them in the third column.
I have also added a 4th column to put your delete user button
<table>
<thead>
<tr>
<th>Username</th>
<th>Listings</th>
<th>Actions</th>
<th></th>
<tr>
</thead>
<tbody>
<tr>
<td>hi</td>
<td>hi</td>
<td><p>ChangeUsername</p></td>
<td>
<form>
<button>Delete User</button>
</form>
</td>
</tr>
<tr>
<td>hi</td>
<td>hi</td>
<td><p>ChangePassword</p></td>
<td>
<form>
<button>Delete User</button>
</form>
</td>
</tr>
</tbody>
</table>
The best way to work with tables is to have the same amount of columns as you do headings for eg adapting your code above:
<table>
<thead>
<tr>
<th>Username</th>
<th>Listings</th>
<th>Actions</th>
<tr>
</thead>
<tbody>
<tr>
<td>hi</td>
<td>hi</td>
<td></td>
</tr>
<tr>
<td>hi</td>
<td>hi</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td>
<a>ChangeUsername</a>
<a>ChangePassword</a>
<form>
<button>Delete User</button>
</form>
</td>
</tr>
</tbody>
</table>
This will show two blank cells then whatever you put in the third (actions headed) cell.
I have a table with html as follows:
<div id="cart">
<table>
<thead>
<tr>
<th>ID</th>
<th>Product Name</th>
<th >Price</th>
<th>Qty</th>
<th >Options</th>
<th >Value</th>
</tr>
</thead>
<tbody>
<tr>
<td class="item-pid">5</td>
<td class="item-name"></td>
<td class="item-price"></td>
<td class="item-quantity">1</td>
<td class="options">color</td>
<td class="item-total">$23.52</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<th>Sub-Total</td>
<td class="third">5</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<th>Shipping Option</td>
<td class="third">EMS</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<th>Grand Total</td>
<td class="third">100</td>
</tr>
<CAPTION ALIGN="bottom">
This is the table's bottom caption
</CAPTION>
</tbody>
</table>
</div>
I need the last three row columns Sub-total, shipping option and grand total to be as a standalone single column with all td 's prior to it removed. currently i am adding:
<td><td><td><td>
to align it to right. All prior cells are displaying blank. I want all those cells removed and the last 3 cells aligned to right.
How is that possible?
I have a Fiddle Demo here..
Help Requested. Thanks in advance.
You can change those 3 rows code into this:
<tr>
<td colspan="5" style="text-align:right;">Sub-Total</td>
<td class="third">5</td>
</tr>
<tr>
<td colspan="5" style="text-align:right;">Shipping Option</td>
<td class="third">EMS</td>
</tr>
<tr>
<td colspan="5" style="text-align:right;">Grand Total</td>
<td class="third">100</td>
</tr>
You can use colspan to merge the colums and text-align:right for the text to align right.
Check out this Fiddle..
I have a basic HTML table like so:
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
I want to add a toolbar above it. Would it be semantically acceptable to add a toolbar as a row in the thead?
<table>
<thead>
<tr>
<th colspan="2">
<!-- toolbar buttons -->
</th>
</tr>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
IMHO, since the toolbar is related to the tabular data, I see no semantic issue with having that toolbar live in a row in the thead.
How can I make a table which has sub/nested tables scrollable if given a max height? I do not want the thead to scroll with it. What I'm really looking for is some valid tag that I can wrap my s in, or some other markup that will work just as well as the this:
<table>
<thead>
<tr>
<th>Column1</th>
<th>Column2</th>
</tr>
</thead>
<!-- Insert valid tag here to wrap <tbody>s -->
<tbody>
<tr>
<td>Val1</td>
<td>Val2</td>
</tr>
<tr class="sub-table">
<td colspan="2">
<table>
<thead>
<tr>
<th>Sub Column1</th>
<th>Sub Column2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sub Val1</td>
<td>Sub Val2</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
<tbody>
<tr>
<td>Val1</td>
<td>Val2</td>
</tr>
<tr class="sub-table">
<td colspan="2">
<table>
<thead>
<tr>
<th>Sub Column1</th>
<th>Sub Column2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sub Val1</td>
<td>Sub Val2</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
<!-- Insert valid close tag here -->
</table>
If I understand your question correctly, maybe try something like this: http://jsfiddle.net/pPuXL/1/
You need to display the TBODY elements as "block" or "inline-block" in order for overflow to work on it, as in the CSS example I posted.