HTML Table with spaces [duplicate] - html

This question already has answers here:
Set cellpadding and cellspacing in CSS?
(19 answers)
Closed 1 year ago.
This is an easy question, but it's super frustrating for someone who is not using html for ages. My html table can be seen at the following:
https://jsfiddle.net/mr_muscle/Lw5o7ary/
with below html:
<table>
<thead>
<tr>
<th>Account status:</th>
<th>Portfolios invested:</th>
<th>Date joined:</th>
<th>MangoPay status:</th>
<th>NorthRow status:</th>
<th>Investor type:</th>
</tr>
</thead>
<tbody>
<tr>
<td>status</td>
<td>Number of portfolios</td>
<td>17 Feb, 2019</td>
<td>Approved</td>
<td>Approved</td>
<td>Inexperienced</td>
</tr>
<tr>
<td colspan='2'>Suspend user</td>
<td colspan='2'>Member for 1 y, 10m</td>
<td>Change</td>
</tr>
</tbody>
Which will give me tables without spaces. How to achieved something similar to this:

Change Style accordingly
table {
border-collapse: separate;
border-spacing: 0 15px;
}
th {
margin: 10px;
padding: 25px;
}
td {
margin: 51px;
padding: 29px;
}
<table>
<thead>
<tr>
<th>Account status:</th>
<th>Portfolios invested:</th>
<th>Date joined:</th>
<th>MangoPay status:</th>
<th>NorthRow status:</th>
<th>Investor type:</th>
</tr>
</thead>
<tbody>
<tr>
<td>status</td>
<td>Number of portfolios</td>
<td>17 Feb, 2019</td>
<td>Approved</td>
<td>Approved</td>
<td>Inexperienced</td>
</tr>
<tr>
<td colspan='2'>Suspend user</td>
<td colspan='2'>Member for 1 y, 10m</td>
<td>Change</td>
</tr>
</tbody>
</table>

You can add a padding to your table cells:
td {
padding-left: 20px;
padding-right: 20px;
}
<table>
<thead>
<tr>
<th>Account status:</th>
<th>Portfolios invested:</th>
<th>Date joined:</th>
<th>MangoPay status:</th>
<th>NorthRow status:</th>
<th>Investor type:</th>
</tr>
</thead>
<tbody>
<tr>
<td>status</td>
<td>Number of portfolios</td>
<td>17 Feb, 2019</td>
<td>Approved</td>
<td>Approved</td>
<td>Inexperienced</td>
</tr>
<tr>
<td colspan='2'>Suspend user</td>
<td colspan='2'>Member for 1 y, 10m</td>
<td>Change</td>
</tr>
</tbody>
</table>

Related

How do I give one single data to a whole column in a HTML table?

I am trying to create a table using HTML like this:
I wrote something like this:
<table>
<caption>Bill Summary</caption>
<tr>
<th rowspan="2">Months</th>
<th colspan="3">Bills</th>
<th rowspan="2">Total</th>
</tr>
<tr>
<td>Electricity</td>
<td>Water</td>
<td>Gas</td>
<td align="center">9925</td>
</tr>
<tr>
<td>January</td>
<td>1000</td>
<td>1000</td>
<td>975</td>
</tr>
<tr>
<td>February</td>
<td>1200</td>
<td>1200</td>
<td>975</td>
</tr>
<tr>
<td>March</td>
<td>1500</td>
<td>1100</td>
<td>975</td>
</tr>
</table>
But it gives out put like this:
I need to have that one total amount aligned in the center and a border like the first table image
Thanks in Advance.
I guess you could use the rowspan attribute here as well.
table, th, td {
border: 1px solid;
border-collapse: collapse;
}
<!DOCTYPE html>
<html>
<body>
<table>
<caption>Bill Summary</caption>
<tr>
<th rowspan="2">Months</th>
<th colspan="3">Bills</th>
<th rowspan="2">Total</th>
</tr>
<tr>
<th>Electricity</th>
<th>Water</th>
<th>Gas</th>
</tr>
<tr>
<td>January</td>
<td>1000</td>
<td>1000</td>
<td>975</td>
<td rowspan="3">9925</td>
</tr>
<tr>
<td>February</td>
<td>1200</td>
<td>1200</td>
<td>975</td>
</tr>
<tr>
<td>March</td>
<td>1500</td>
<td>1100</td>
<td>975</td>
</tr>
</table>
</body>
</html>
move total value to third row and modify like this
<td align="center" style="vertical-align: middle" rowspan="3" >9925</td>

Table markup using HTML

I need to make markup for creating the next table (using HTML):
task
Here is my way of making that (doesn't work):
Step 1: Making "general" markup with all cells of equal size:
td { border: solid #aaa 1px }
<table>
<thead>
<tr>
<th colspan="4">Some Table</th>
</tr>
</thead>
<tbody>
<tr>
<td>1.1</td>
<td>1.2</td>
<td>1.3</td>
<td>1.4</td>
</tr>
<tr>
<td>2.1</td>
<td>2.2</td>
<td>2.3</td>
<td>2.4</td>
</tr>
<tr>
<td>3.1</td>
<td>3.2</td>
<td>3.3</td>
<td>3.4</td>
</tr>
</tbody>
</table>
Output: Step 1
Step 2: Using "colspan" and "rowspan" for making cells 1.3 and 2.1 bigger and deleting unnecessary cells (1.4, 2.3, 2.4, 3.3 and 3.4), except one (2.2 , just for now): Step 2
Step 3: As soon as I delete cell 2.2 - big cells (1.3 and 2.1) become "smaller": Step 3 and it isn't what I need...
Here is my final markup:
td { border: solid #aaa 1px }
<table>
<thead>
<tr>
<th colspan="4">Some Table</th>
</tr>
</thead>
<tbody>
<tr>
<td>1.1</td>
<td>1.2</td>
<td colspan="2" rowspan="2">1.3</td>
</tr>
<tr>
<td colspan="2" rowspan="2">2.1</td>
</tr>
<tr>
<td>3.1</td>
<td>3.2</td>
</tr>
</tbody>
</table>
I can't find out how to delete cell 2.2 and keep table's shape as it mentioned in the task... Appreciate any help.
Here is we Achieve the Output
table,
tr,
td {
border: 1px solid black;
}
table {
border-collapse: collapse;
}
tr {
height: 30px;
}
td {
height: 30px;
width: 50px;
text-align: center;
}
<table>
<tr>
<td>1.1</td>
<td>1.2</td>
<td colspan="2" rowspan=2>1.3</td>
</tr>
<tr>
<td colspan="2" rowspan="2">2.1</td>
</tr>
<tr>
<td>3.1</td>
<td>3.2</td>
</tr>
</table>
You should try to this code
td {
border: 1px solid #579;
}
<table>
<tbody>
<tr>
<td>1.1</td>
<td>1.2</td>
<td colspan="2">1.3</td>
</tr>
<tr>
<td colspan="2" rowspan="2">2.1</td>
<td>2.2</td>
<td>2.3</td>
</tr>
<tr>
<td>3.1</td>
<td>3.2</td>
</tr>
</tbody>
</table>
You should try this
<style>td{border:1px solid black;}
tr{height:35px;}
</style>
<table>
<tbody>
<tr>
<td colspan="4">Head</td>
</tr>
<tr>
<td>1.1</td>
<td>1.2</td>
<td colspan="2" rowspan="2">1.3</td>
</tr>
<tr>
<td colspan="2" rowspan="2">2</td>
</tr>
<tr>
<td>3.1</td>
<td>3.2</td>
</tr>
</tbody>
</table>

A very simple html table [duplicate]

This question already has answers here:
How do you use colspan and rowspan in HTML tables?
(11 answers)
Closed 5 years ago.
I need to make the table like below:
Here is my code, logically everything seems to be written correctly, but if you remove the extra cell, then everything breaks. in what there can be an error?
<table border=1>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
<tr>
<td>Four</td>
<td>Five</td>
<td rowspan=2>Six</td>
</tr>
<tr>
<td rowspan=2>Seven</td>
<td rowspan=2>Eight</td>
<td>Extra</td>
</tr>
<tr>
<td>Nine</td>
</tr>
</table>
Here you are - i just added a second line of text to the higher/merged cells, but it (only) works without that "Extra" cell:
table {
border-collapse: collapse;
}
td {
border: 1px solid #444;
}
<table>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
<tr>
<td>Four</td>
<td>Five</td>
<td rowspan=2>Six<br>X</td>
</tr>
<tr>
<td rowspan=2>Seven<br>X</td>
<td rowspan=2>Eight<br>X</td>
</tr>
<tr>
<td>Nine</td>
</tr>
</table>

Table Background Image Displaying in Front of Table

After adding a background image to my table, the image is displaying over the table and the contents of the table are hidden. Why is this? HTML and CSS code is below:
.muscles_worked {
background-image: url(images/dumbbell.png);
border: 1px dashed black;
margin: 0 auto;
margin-top: 50px;
}
<table class="muscles_worked">
<caption>Muscles Worked in this Program</caption>
<thead>
<tr>
<th>Part of Body</th>
<th>Day(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">Legs</td>
<td>Monday</td>
</tr>
<tr>
<td>Friday</td>
</tr>
<tr>
<td rowspan="3">Core</td>
<td>Monday</td>
</tr>
<tr>
<td>Thursday</td>
</tr>
<tr>
<td>Friday</td>
</tr>
</tbody>
</table>
A better way might be to set the table in a div and set the background on that.
div.muscles_worked {
background-image: url('http://placekitten.com/700/500?image=13');
margin: 0 auto;
margin-top: 50px;
display: inline-block;
}
.muscles_worked > table {
border: 1px dashed black;
}
<div class="muscles_worked">
<table>
<caption>Muscles Worked in this Program</caption>
<thead>
<tr>
<th>Part of Body</th>
<th>Day(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">Legs</td>
<td>Monday</td>
</tr>
<tr>
<td>Friday</td>
</tr>
<tr>
<td rowspan="3">Core</td>
<td>Monday</td>
</tr>
<tr>
<td>Thursday</td>
</tr>
<tr>
<td>Friday</td>
</tr>
</tbody>
</table>
</div>
Hope it helps. Cheers!

How can I construct a table header than contains multiple rows in column?

I would like to construct a table as follows:
I am trying to construct same table in html but having trouble. Table header needs to be exact. Any help is helpful
You can use the rowspan attribute:
th {
border:1px solid #000;
height: 20px;
width: 150px;
}
<table>
<thead>
<tr>
<th rowspan="4">#</th>
<th>Name</th>
<th rowspan="2">Permanent Address</th>
<th rowspan="2">Type of Job</th>
<th rowspan="2">Start work</th>
</tr>
<tr>
<th>ID</th>
</tr>
<tr>
<th>M/F</th>
<th rowspan="2">Contract</th>
<th rowspan="2">Place of Work</th>
<th rowspan="2">Work Stops</th>
</tr>
<tr>
<th>Birth</th>
</tr>
</thead>
</table>
FYI: there is also a colspan attribute if you need to span multiple columns.
Try this......
body {
padding: 50px;
}
table {
width: 100%;
border-collapse: collapse;
}
td,
th {
padding: 10px;
border: 1px solid black;
}
<table>
<tbody>
<tr>
<td rowspan="4">#</td>
<td>Name</td>
<td rowspan="2">Permanent Address</td>
<td rowspan="2">Type of Job</td>
<td rowspan="2">Start work</td>
</tr>
<tr>
<td>ID</td>
</tr>
<tr>
<td>M/F</td>
<td rowspan="2">Contract</td>
<td rowspan="2">Place of Work</td>
<td rowspan="2">Work Stops</td>
</tr>
<tr>
<td>Birth</td>
</tr>
</tbody>
</table>