Creating columns inside a column - html

This is the picture of what the output should look like:
I want to create something like this (see the attached photo). But I can't do the same thing. I already tried using div and table tags.
This is what I've been doing
<table class="table table-bordered">
<thead>
<tr>
<th class="col-xs-1">ProjectID</th>
<th>Program/Project</th>
<th class="col-xs-1">Office/Unit</th>
<th class="col-xs-1">General Description</th>
<th class="col-xs-1">Methods</th>
<th> Schedule/Milestone
<table>
<tr>
<td class="col-xs-1">Jan</td>
<td class="col-xs-1">Feb</td>
<td class="col-xs-1">Mar</td>
<td class="col-xs-1">Apr</td>
<td class="col-xs-1">May</td>
<td class="col-xs-1">Jun</td>
<td class="col-xs-1">Jul</td>
<td class="col-xs-1">Aug</td>
<td class="col-xs-1">Sep</td>
<td class="col-xs-1">Oct</td>
<td class="col-xs-1">Nov</td>
<td class="col-xs-1">Dec</td>
</tr>
</table>
</th>
<th class="col-xs-1">Source of funds</th>
<th class="col-xs-1">Approved Budget Ceiling (ABC)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Empty</td>
<td>Empty</td>
<td>Empty</td>
<td>Empty</td>
<td>Empty</td>
<td>
<!-- THIS IS WHERE I CAN'T GET IT RIGHT -->
<table>
<tr>
<td class="col-xs-1">1</td>
<td class="col-xs-1">2</td>
<td class="col-xs-1"> 3</td>
<td class="col-xs-1"> 4</td>
<td class="col-xs-1"> 5</td>
<td class="col-xs-1"> 6</td>
<td class="col-xs-1"> 7</td>
<td class="col-xs-1"> 8</td>
<td class="col-xs-1"> 9</td>
<td class="col-xs-1"> 10</td>
<td class="col-xs-1"> 11</td>
<td class="col-xs-1"> 12</td>
</tr>
</table>
</td>
<td>Empty</td>
<td>Empty</td>
</tr>
</tbody>
</table>
But the output of this code looks like this:
I am using bootstrap to create my website.

What you're trying to do isn't really possible, because you are breaking up the table structure in two. This means that each cell in the 2nd table (1,2,3..) is going to have the width of its' contents and won't be affected by the width of the header cells (Jan, Feb, Mar...).
This is why you're seeing this.
One way to fix this is by applying table-layout: fixed on both tables, and then giving each td a fixed width and the display: inline-block property.
.milestone-table {
table-layout: fixed;
width: 390px; /*optional*/
}
.milestone-table td {
width: 30px;
display: inline-block;
}
Demo

Related

colspan="1.5" not working, any other ideas?

this is what table i need
I can easily get first and second row good but when i'm trying to make row third, I'm destroying row two.
I tried with width attribute and colspan but nothing work.
<table border="1px" width="100%">
<tr>
<td colspan="6">Cell 1</td>
</tr>
<tr >
<td colspan="3">Cell 2</td>
<td colspan="3" >Cell 3</td>
</tr>
<tr>
<td colspan="2">Cell 4</td>
<td colspan="2">Cell 5</td>
<td colspan="2">Cell 6</td>
</tr>
</table>
A <table> will conform to it's content by default so there's no need for each column to be equal in width. So manually assign equal column widths by assigning table-layout: fixed to <table> then an equal width for each column by either assigning each width to the <th> in the <thead> of the first <tr> or lacking that assign widths to the <td> of the first <tr> (of course td or th as a selector works as well), see example below.
table {
table-layout: fixed;
}
td {
width: 16.5%;
text-align: center;
}
<table border="1px" width="100%">
<tr>
<td colspan="6">I</td>
</tr>
<tr>
<td colspan="3">II</td>
<td colspan="3">III</td>
</tr>
<tr>
<td colspan="2">IV</td>
<td colspan="2">V</td>
<td colspan="2">VI</td>
</tr>
</table>

How do I set width of column with rowspan and colspan in table?

I have made an html page to display a status dash board for some of the systems at work. The systems in the first seven rows are kind of interconnected, so in addition to the status for each of them, I want to present the status for the combination of the seven systems. Technically this works great, but I am not entirely happy with the layout. I would like to have the yellow bar at the left to take up a smaller part of the first colum, not half of it.
The first three rows of the table are coded as:
<tr><th id="namehead"></th><th colspan="2" class="typehead">Data</th>
<th class="typehead">Strøm</th><th class="typehead">Komm.</th></tr>
<tr id="sys1"><td id="agg_data" class="data agg" rowspan="7" td><td id="sys1_data"
class="data sys1"></td><td id="sys1_power" class="power sys1"></td><td id="sys1_comm"
class="comm sys1"></td></tr>
<tr id="sys2"><td id="sys2_data" class="data"></td><td id="sys2_power" class="power"></td>
<td id="sys2_comm" class="comm"></td></tr>
Then from the 8th status row, I do:
<tr id="arc"><td id="arc_data" class="data" colspan="2"></td>
<td id="arc_power" class="power"></td><td id="arc_comm" class="comm"></td></tr>
in my css, the class "typehead" has set {width: 100px;}. I have tried to set width on the cells of the first status row, although it does not give me any kind of errors, it does not work either (firefox and chrome) Is it somehow possible to achieve this in css?
Most likely the content is stretching the table cell. You can avoid this if you wrap the content in a div and size it as needed. And, as an option, arrange the text vertically.
.typehead {
width: 100px;
font: bold 20px/1 sans-serif;
color: #e3e3e3;
background-color: #262626;
}
td {
padding: 4px;
text-align: right;
background-color: #31a72c;
}
tr:nth-child(2) td:nth-child(1) {
width: 1em;
background-color: #ffee52;
}
.vertical {
writing-mode: vertical-rl;
transform: rotate(.5turn);
}
<table>
<tr>
<!--th id="namehead"></th-->
<th colspan="2" class="typehead">Data</th>
<th class="typehead">Strøm</th>
<th class="typehead">Komm.</th>
</tr>
<tr id="sys1">
<td id="agg_data" class="data agg" rowspan="7">
<div class='vertical'>agg_data</div>
</td>
<td id="sys1_data" class="data sys1">sys1_data</td>
<td id="sys1_power" class="power sys1">sys1_power</td>
<td id="sys1_comm" class="comm sys1">sys1_comm</td>
</tr>
<tr id="sys2">
<td id="sys2_data" class="data">sys2_data</td>
<td id="sys2_power" class="power">sys2_power</td>
<td id="sys2_comm" class="comm">sys2_comm</td>
</tr>
<tr id="sys3">
<td id="sys3_data" class="data">sys3_data</td>
<td id="sys3_power" class="power">sys3_power</td>
<td id="sys3_comm" class="comm">sys3_comm</td>
</tr>
<tr id="sys4">
<td id="sys4_data" class="data">sys4_data</td>
<td id="sys4_power" class="power">sys4_power</td>
<td id="sys4_comm" class="comm">sys4_comm</td>
</tr>
<tr id="sys5">
<td id="sys5_data" class="data">sys5_data</td>
<td id="sys5_power" class="power">sys5_power</td>
<td id="sys5_comm" class="comm">sys5_comm</td>
</tr>
<tr id="sys6">
<td id="sys6_data" class="data">sys6_data</td>
<td id="sys6_power" class="power">sys6_power</td>
<td id="sys6_comm" class="comm">sys6_comm</td>
</tr>
<tr id="sys7">
<td id="sys7_data" class="data">sys7_data</td>
<td id="sys7_power" class="power">sys7_power</td>
<td id="sys7_comm" class="comm">sys7_comm</td>
</tr>
<tr id="arc">
<td id="arc_data" class="data" colspan="2">arc_data</td>
<td id="arc_power" class="power">arc_power</td>
<td id="arc_comm" class="comm">arc_comm</td>
</tr>
<tr id="arc">
<td id="arc_data" class="data" colspan="2">arc_data</td>
<td id="arc_power" class="power">arc_power</td>
<td id="arc_comm" class="comm">arc_comm</td>
</tr>
<tr id="arc">
<td id="arc_data" class="data" colspan="2">arc_data</td>
<td id="arc_power" class="power">arc_power</td>
<td id="arc_comm" class="comm">arc_comm</td>
</tr>
<tr id="arc">
<td id="arc_data" class="data" colspan="2">arc_data</td>
<td id="arc_power" class="power">arc_power</td>
<td id="arc_comm" class="comm">arc_comm</td>
</tr>
<tr id="arc">
<td id="arc_data" class="data" colspan="2">arc_data</td>
<td id="arc_power" class="power">arc_power</td>
<td id="arc_comm" class="comm">arc_comm</td>
</tr>
</table>

HTML table row with double height

I am trying to add a row with double height to that of other row. But unable to make. Not sure what is wrong.
<table border="1">
<tr>
<td rowSpan="2">A1</td>
<td rowSpan="2">A2</td>
<td rowSpan="2">A3</td>
<td rowSpan="2">A4</td>
</tr>
<tr>
</tr>
<tr>
<td>C1</td>
<td>C2</td>
<td>C3</td>
<td>C4</td>
</tr>
</table>
You'll need some css to set the height of the row;
table td, tr {
height: 30px;
}
table td, tr {
height: 30px;
}
<table border="1">
<tbody>
<tr>
<td rowSpan="2">A1</td>
<td rowSpan="2">A2</td>
<td rowSpan="2">A3</td>
<td rowSpan="2">A4</td>
</tr>
<tr>
</tr>
<tr>
<td>C1</td>
<td>C2</td>
<td>C3</td>
<td>C4</td>
</tr>
</tbody>
</table>
Note; You should add a tbody to your table; What is the purpose for HTML's tbody?
Are you trying to do that ?
<table border="1">
<tr>
<td>A1</td>
<td>A2</td>
<td>A3</td>
<td rowspan="2">A4/B4 <br>(2 rows)</td>
</tr>
<tr>
<td>B1</td>
<td>B2</td>
<td>B3</td>
</tr>
<tr>
<td>C1</td>
<td colspan="2">C2/C3 <br>(2 cols)</td>
<td>C4</td>
</tr>
</table>
The rowspan property should only be used if you are trying to have one cell appear across two rows (as if you are using the Merge Cells functionality on Excel). If you want to make one row twice as high as the other, this is a display property and should be done with css or inline styling. The middle (row) should also be removed.
If this is just a general example and you need to use it on something more complex. If you use rowspan on say 1 element, you will need to make sure that the following row has 1 less td element otherwise it will not display correctly.
<table border="1">
<tr style="height: 50px">
<td >A1</td>
<td >A2</td>
<td >A3</td>
<td >A4</td>
</tr>
<tr>
<td>C1</td>
<td>C2</td>
<td>C3</td>
<td>C4</td>
</tr>
</table>

How to design an HTML Table with different rowspan?

I've been designing webpages for some time now, and for one of my webpages, I need to design a table with 6 columns and 3 rows. The first column need to have 3 rows, while the other 5 columns only need 2 rows. I can make it using this CODE:
<tr><td class="style3">7:00 AM
</td>
<td class="style3" rowspan="2">
</td>
<td class="style3" rowspan="2">
</td>
<td class="style3" rowspan="2">
</td>
<td class="style3" rowspan="2">
</td>
</tr>
<tr><td class="style3">7:30 AM
</td>
</tr>
<tr><td class="style3">7:59 AM
</td>
<td class="style3">
</td>
<td class="style3">
</td>
<td class="style3">
</td>
<td class="style3">
</td>
</tr>
How can I make it so that the bottom border of the first row of the 5 columns are exactly in the middle of the second row of the first column?
It means that the line of the bottom border of the first row of the 5 columns is in the middle of the value "7:30 AM" from the first column, second row. I know it is quite confusing but I cannot show you an image of how I want it to look like because I just join here and I don't have 10 reputations to post an image. Please understand my logic.
rowspan=2 means, the column will span two rows, hence if you are applying this to the first column of the first row, the the next row should have one less column. For every column you do a rowspan="n" on, you need to omit that column from the next "n-1" number of rows.
The following snippet will make it clear to you:
table, td {
border: 1px solid gray;
border-collapse: collapse;
}
td { padding: 8px; }
<table>
<tbody>
<tr>
<td class="style3">7:00 AM</td>
<td class="style3" rowspan="2">Event 1</td>
<td class="style3" rowspan="2">Event 2</td>
<td class="style3" rowspan="2">Event 3</td>
<td class="style3" rowspan="2">Event 4</td>
</tr>
<tr>
<td class="style3" rowspan="2"></td>
</tr>
<tr>
<td class="style3" rowspan="2">Event 5</td>
<td class="style3" rowspan="2">Event 6</td>
<td class="style3" rowspan="2">Event 7</td>
<td class="style3" rowspan="2">Event 8</td>
</tr>
<tr>
<td class="style3">7:59 AM</td>
</tr>
</tbody>
</table>

Shrinking one cell in a table

I am trying to shrink one cell in the table, but it refuses to shring..here is my table.
<table cellspacing="0" style="position: absolute;width: 990px;margin-left: 8px;" align="center">
<thead>
<tr class='no-wrap'>
<th width="20%"></th>
<th width="10%">Our Rating</th>
<th width="10%">Users' Rating</th>
<th width="30%">Review</th>
<th width="30%">Price</th>
</tr>
</thead>
<tbody>
<tr>
<td width="20%"></td>
<td width="10%">Our Rating</td>
<td width="10%">Users' Rating</td>
<td width="30%">Review</th>
<td width="30%">Price</td>
</tr>
</tbody>
</table>
The problem is that the review part doesnt shrink..even when I give it a lower percentage..why is that?
You have incorrect HTML syntax.
You need to wrap your table row elements in tr:
<tbody>
<tr>
<td></td>...
</tr>
</tbody>
Also you have a </th> where you should have a <td> on your 2nd row, 4th cell (Review):
<td width="30%">Review</th>