HTML Table colspan rowspan - html

I have 6 columns & I want to use colspan for 3&4 and 5&6 column.
And I don't want to show 1st & 2nd column for that particular row.
How to hide 1&2 column in that row?
Desired output..

Remove the border from the cells you wish to "hide". They are still there, but visually absent.
Have a fiddle!
Experimental fiddle for a table { border: xxx; } fix.
In this example I am targeting the cell with tbody tr:first-child td:first-child. This could obviously also be targeted with a class.
HTML
<table>
<tbody>
<tr>
<td colspan="2"></td>
<td colspan="2"></td>
<td colspan="2"></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
CSS
table {
border-collapse: collapse;
width: 500px;
}
td {
border: solid 1px #000;
padding: 10px;
}
tbody tr:first-child td:first-child {
border: none;
}

Use display:none; in your CSS File on the 1st & 2nd Column.
You can select them with:
td:nth-of-type(1),
td:nth-of-type(2) {
display:none;
}

Use visibility:hidden on the first two columns of the row.

Try to use visibility: hidden; empty-cells: hide; for that cells.

Here is a fiddle
HTML
<table border="1">
<thead>
<tr>
<td colspan="2" style="border: 0;">a1</td>
<td colspan="2">a3</td>
<td colspan="2">a5</td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>5555</td>
</tr>
</tbody>
</table>
CSS
table {
border: none;
border-collapse: collapse;
}

Related

html table : is it possible to style inexistant cells or must I add them to the code?

context :
I work on a little csv-like script editor,
and I use an html table to display the data
As you can see there are missing cells.
That was to be expected, since I only insert the cells containing data
(and the previous cells of the row),
and the border style is only applied on cell elements for now.
I'd like All the cells to be displayed,
and I wondered if it was possible to draw the table lines
without cells, or if the only solution is to insert the missing cells ?
minimum reproducible example :
<table>
<tr>
<td>A1</td>
</tr>
<tr>
<td></td>
<td>B2</td>
</tr>
<tr>
<td></td>
<td></td>
<td>C3</td>
</tr>
</table>
<style>
table {
border-collapse: collapse;
border: 2px solid #555;
}
td {
border: 1px solid #888;
}
</style>
As we know elements who do now exist will not shown you have to add as needed to your table with no data in it. and you can set your code like below.
table {
border-collapse: collapse;
border: 2px solid #555;
empty-cells: show;
}
td {
border: 1px solid #888;
}
<table>
<tr>
<td>A1</td>
</tr>
<tr>
<td></td>
<td>B2</td>
</tr>
<tr>
<td></td>
<td></td>
<td>C3</td>
</tr>
</table>

Html table design issues with row data

I am facing issues with designing this table below as per image:
I tried below table basic html table tr > td structure but nothing is helping me to get desired output.
Use the rowspan attribute like so:
#table1 {
width: 100%;
border-collapse: collapse;
}
#table1 td {
border: 1px solid black;
}
<table id="table1">
<tr>
<td>Estimated Time</td>
<td>1</td>
</tr>
<tr>
<td rowspan="2">Delivery Charge</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>Payment Method</td>
<td>4</td>
</tr>
</table>

img inside table row with tr width

How can I do this with CSS?
https://jsfiddle.net/ou8sdfLo/
I want to put an <img> inside a <tr> with a widh equal to its <tr>.
I hope it is clear enough.
I modified the image to match the code.
The image needs to be in a td, and if you want that td to span the entire width of the tr use the colspan attribute. Then if you want the img to fill the width of the td, use display: block; width: 100%;
table {
border-collapse: collapse;
}
tbody tr:hover {
background: #eee;
}
td:first-child {
text-align: left;
}
th {
background: #888;
color: white;
}
td,
th {
padding: 0.75em;
text-align: center;
}
img {
width: 100%;
display: block;
}
<table>
<tr>
<th>Model</th>
<th>Max speed</th>
<th>Power</th>
<th>Swept volume</th>
<th>Weight</th>
</tr>
<tr>
<td>Car 1</td>
<td>45 mph (72 km/h)</td>
<td>22 hp</td>
<td>2865 ccm</td>
<td>800 kg</td>
</tr>
<tr>
<td colspan="5"><img src="http://placehold.it/350x150" alt="car_preview"></td>
</tr>
<tr>
<td>Car 2</td>
<td>45 mph (72 km/h)</td>
<td>22 hp</td>
<td>2865 ccm</td>
<td>800 kg</td>
</tr>
</table
The only valid tag within a <tr> is <td>.
In the <img> row, you would need to set a colspan on your <td> equal to the total number of columns.
Like this:
<table>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="6"></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>

Designing complex table layout using html and css

I am trying to design the following table using html and css how do I proceed with it. Thank you in advance.
This solution will save you from having to use nested tables. The trick is that you really have four rows, not three, and make use of colspan and rowspan.
Note that you need to set a height for the td in order to ensure they are even.
table {
width: 100%;
border-collapse: collapse;
}
td {
border: 1px solid black;
height: 30px;
}
<table>
<tr>
<td colspan="2"></td>
<td rowspan="2"></td>
</tr>
<tr>
<td rowspan="2"></td>
<td rowspan="2"></td>
</tr>
<tr>
<td rowspan="2"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
you can try this one:
HTML
<table>
<tr>
<td>
<table>
<tr>
<td colspan="2">Th</td>
</tr>
<tr>
<td>Th</td>
<td>Th</td>
</tr>
<tr>
<td>Th</td>
<td>Th</td>
</tr>
</table>
</td>
<td>Th</td>
</tr>
</table>
CSS
table
{
width:100%;
height:100px;
text-align:center;
border:2px solid gray;
border-collapse: collapse;
}
td
{
border:2px solid gray;
}
.container
{
width:100%;
}
.container .header
{
width:100%;
height:200px;
background:#5076BB;
}
.container .slider
{
width:100%;
height:500px;
background:#5076BB;
}
DEMO HERE
UPDATED DEMO HERE
Read the tutorial: http://www.w3schools.com/html/html_tables.asp
In particular read the part about the attributes rowspan="" and colspan=""
Example:
<td colspan="2">This table data will span two columns</td>
<td rowspan="2">This table data will span two rows</td>

A way to group table cells together in html?

So it is pretty straight forward. I need a way to group cells together. Like a <div> or a <span> but none of them worked. <tbody> seemed like a good solution but it only works for table rows. Help!
If you're looking for a way to merge 2 o more cells in a row into one single cell, along with other "regular" cells (as you would do in a google|excel spreadsheet) in a way similar to this:
then you can use the colspan attribute for td elements, indicating how many cells are you merging:
<tr>
<td colspan=2> Merged Cell occupying 2 columns </td>
</tr>
<tr>
<td> Regular cell </td>
<td> Another cell in same row </td>
</tr>
Additionally, you can use the td[colspan] selector in css (combined with any parent selector of your choice) to refer to these merged cells.
Here's a working example:
/* Style for cells with any colspan attribute */
td[colspan] {
text-align: center;
}
/* No extra space between cells */
table {
border-collapse: collapse;
}
th, td {
border: 1px solid gray;
margin: 0;
padding: 3px 10px;
text-align: right;
}
<table>
<tr>
<th>Day</th>
<th>Invoice</th>
<th>Total</th>
</tr>
<tr>
<!-- this cell will occupy 3 columns -->
<td colspan=3>January</td>
</tr>
<tr>
<td>2</td>
<td>0348</td>
<td>248.35</td>
</tr>
<tr>
<td>7</td>
<td>0349</td>
<td>126.14</td>
</tr>
<tr>
<td>18</td>
<td>0350</td>
<td>821.99</td>
</tr>
<tr>
<td colspan=3>February</td>
</tr>
<tr>
<td>27</td>
<td>0351</td>
<td>643.50</td>
</tr>
</table>
You can add the html col tag to group the columns td.
.col-group-1 {
background-color: yellow;
}
.col-group-2 {
background-color: silver;
}
<table>
<colgroup>
<col class="col-group-1">
<col span="2" class="col-group-2">
</colgroup>
<tr>
<th>Name</th>
<th>City</th>
<th>Phone</th>
</tr>
<tr>
<td>Mary</td>
<td>New york</td>
<td>987654321</td>
</tr>
<tr>
<td>Magdalena</td>
<td>Los Angeles</td>
<td>123456789</td>
</tr>
</table>
</body>
</html>
Please check out the html col tag
and how to use them with css styling