Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I would like to create for example below html tables, It bsically come from square tables.
I tried sometimes, but I couldn't figure out how to change height of each cells.
If someone has opinion, please let me know.
Thanks
table {
border-collapse:collapse;}
td {
padding:5px;
border:solid black 1px;}
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</table>
Maybe with the :empty CSS pseudo-class?
Removing the padding of empty table cells:
table {
border-collapse:collapse;
}
td {
padding:5px;
border:solid black 1px;
}
td:empty {
padding: 0;
}
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</table>
Not displaying empty table cells.
table {
border-collapse:collapse;
}
td {
padding:5px;
border:solid black 1px;
}
td:empty {
display: none !important;
}
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</table>
If I'm reading you right my solution is to add specific classes to the cells that you'd like to be different, that way you can specify the different in padding of the cells with numbers.
table {
border-collapse:collapse;}
td {
padding:25px;
border:solid black 1px;}
.tall {
padding-right:100px;
padding-bottom:100px;
}
<table>
<tr>
<td class="tall">1</td>
<td class="tall">2</td>
<td class="tall">3</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td class="tall">4</td>
<td class="tall">5</td>
<td class="tall">6</td>
</tr>
</table>
Check out my codepen here:
https://codepen.io/danhebdon/pen/RwPzzvm
Here is a duplicate version of the original table:
table {
width: 100%;
border: 3px solid gray;
border-collapse:collapse;
font-family: 'Arial', sans-serif;
font-size: 36px;
}
td {
border: 3px solid gray;
height: 200px;
text-align: top;
padding: 12px;
}
.smallheight {
height: 50px;
}
<table>
<tr>
<td valign="top">1</td>
<td valign="top">2</td>
<td valign="top">3</td>
</tr>
<tr>
<td class="smallheight"></td>
<td class="smallheight"></td>
<td class="smallheight"></td>
</tr>
<tr>
<td class="smallheight"></td>
<td class="smallheight"></td>
<td class="smallheight"></td>
</tr>
<tr>
<td class="smallheight"></td>
<td class="smallheight"></td>
<td class="smallheight"></td>
</tr>
<tr>
<td valign="top">4</td>
<td valign="top">5</td>
<td valign="top">6</td>
</tr>
</table>
CodePen: https://codepen.io/marchmello/pen/KKpjjvz
Related
I've created a simple table using html and a bit of bootstrap, but the last rowspan doesn't work as I thought it will, here's code:
I wanted 4 red-marked cells to be one, so I've replaced first <td>group1</td> with <td rowspan="4">group1</td> and removed remaining 3 <td>group1</td> but it has messed up whole table.
Also it is placed it <div class="col-lg-7 mb-4"> div, but I've also tried without any div - the effect was the same. I'm not sure what is causing that problem, considering that the rest rowspans is working just fine.
/* I don't think CSS is needed, but just in case: */
table.table-bordered {
border: 1px solid #2f8dff!important;
box-shadow: 0px 0px 100px 0px #2f8dff;
margin-top: 20px;
text-transform: uppercase;
font-size: 12px;
color: white;
}
table.table-bordered>thead>tr>th {
border: 1px solid #2f8dff!important;
}
table.table-bordered>tbody>tr>td {
border: 1px solid #2f8dff!important;
}
<table class="table table-bordered">
<thead>
<tr>
<th></th>
<th>mon</th>
<th>tue</th>
<th>wed</th>
<th>thu</th>
<th>fri</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">17:00-18:00</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
</tr>
<tr>
<td rowspan="2">18:00-19:00</td>
<td>1</td>
<td rowspan="2">group3</td>
<td>3</td>
<td>4</td>
<td rowspan="2">group3</td>
</tr>
<tr>
<td rowspan="2">group2</td>
<td>8</td>
<td rowspan="2">group2</td>
</tr>
<tr>
<td rowspan="2">19:00-20:00</td>
<td rowspan="4">group1</td>
<td rowspan="2">group1</td>
<td>group1</td>
</tr>
<tr>
<td rowspan="3">group1</td>
<td rowspan="3">group1</td>
<td>group1</td>
</tr>
<tr>
<td rowspan="2">20:00-21:00</td>
<td>3</td>
<td>group1</td>
</tr>
<tr>
<td>7</td>
<td>group1</td>
</tr>
</tbody>
</table>
What shall I do?
Thanks in advance!
I don't really know what you mean by "messed up whole table". After adding the row-span="4" and removing the three following td tags, the table looked just fine for me:
The only thing I can see is the changing height of that table cell. This can be prevented by adding this CSS:
tr {
height: 1rem;
}
It makes every row equal height and produces following result:
I have a table with different number of <td>, something like this:
<table>
<tbody><tr><td>1</td><td>2</td><td>3</td><td>4</td>
</tr></tbody>
<tbody><tr><td>1</td>
</tr></tbody>
<tbody><tr><td>1</td><td>2</td>
</tr></tbody>
<tbody><tr><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td>
</tr></tbody>
</table>
I want to draw a line under every row, I tried these styles:
table{border-collapse: collapse;empty-cells: show;}
tbody{border-bottom:1px solid #000;}
tr{border-bottom:1px solid #000;}
td{border-bottom:1px solid #000;}
This is what I get:
Lines are not reaching the end of the table, this is the expected result:
Is this possible using css only?
table{border-collapse: collapse;empty-cells: show;}
tbody{border-bottom:1px solid #000;}
tr{border-bottom:1px solid #000;}
td{border-bottom:1px solid #000;}
<table>
<tbody><tr><td>1</td><td>2</td><td>3</td><td>4</td>
</tr></tbody>
<tbody><tr><td>1</td>
</tr></tbody>
<tbody><tr><td>1</td><td>2</td>
</tr></tbody>
<tbody><tr><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td>
</tr></tbody>
</table>
Use a pseudo element to create a long line and hide the overflow:
table {
border-collapse: collapse;
empty-cells: show;
overflow: hidden;
}
td {
position: relative;
padding: 5px;
}
td:first-child:before {
content: "";
position: absolute;
bottom: 0;
left: 0;
right: -100vw;
;
height: 1px;
background: #000;
}
<table>
<tbody>
<tr>
<td>111</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>33</td>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</tbody>
</table>
Your new code:
table {
border-collapse: collapse;
empty-cells: show;
}
tr {
border-bottom: 1px solid #000;
display: block;
}
<table>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</tbody>
<tbody>
<tr>
<td>1</td>
</tr>
</tbody>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
</tbody>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</tbody>
</table>
Just changed the display CSS property of the rows to block.
This isn't the perfect solution for dynamic data so I would suggest making a table out of divisions and CSS.
I also suggest that you accept #Temani Afif answer since it is better than mine in the way that you can keep your table structure as well using the pseudo elements.
I tried using boxed elements but it is not coming in a proper way!
Any kind of help is highly appreciated
https://codepen.io/saisree/pen/EXXQGO - link to codepen
<table>
<tr>
<td class="text-center" colspan="4">Aircraft Status Display</td>
</tr>
<tr>
<td> spare</br>STBY</td><td><div class="vr"></div>
</td>
</tr>
<tr>
<td style="width:80px;" ><p style="padding-top:20px;padding-bottom:20px;" class="boxed4 text-center"
><span class="br"></span></p>
</td>
<td style="width:80px;" ><p style="padding-top:20px;padding-bottom:20px;" class="boxed4 text-center"
><span class="br"></span></p>
</td>
<td style="width:80px;" ><p style="padding-top:20px;padding-bottom:20px;" class="boxed4 text-center"
><span class="br"></span></p>
</td>
</table>
Using colspan=n to make a column the width of n columns:
<table>
<tr>
<td></td><td colspan="6">this is wide column</td>
</tr>
<tr>
<td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
<td></td><td colspan="6">another wide column</td>
</tr>
<tr>
<td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
</table>
It's not completely clear from your image what you are trying to achieve, but if you mean the "half-open" cells, here is an example.
It uses col-spans to merge several cells into one, and different border settings: First a default setting for all cells (for borders on each side), the therse are overwritten by additional CSS rules that have special CSS selectors (with pseudo classes) to only affect certain cells:
table {
border-collapse: collapse;
width: 60%;
margin: 0 auto;
}
td {
border: 1px solid #333;
height: 40px;
}
tr:first-of-type > td {
border-bottom: none;
height: 20px;
}
tr:nth-of-type(2) > td {
border-top: none;
height: 40px;
}
tr:nth-of-type(4) > td:not(:first-child) {
border-bottom: none;
}
tr:nth-of-type(5) > td:not(:first-child) {
border-top: none;
}
<table>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="4" ;></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="4" ;></td>
</tr> <tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
This question already has answers here:
HTML table with fixed headers?
(31 answers)
Closed 7 years ago.
I know how to make a fixed table-header a few different ways, however I'm looking for the best way, and I only want to use <table>,<thead>,<tbody>,<tr>,<th>,<td> tags which the HTML spec provides you.
Here is a dummy table structure:
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>field</th>
<th>facility</th>
<th>change</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>name1</td>
<td>field1</td>
<td>facility1</td>
<td>change1</td>
</tr>
<tr>
<td>2</td>
<td>name2</td>
<td>field2</td>
<td>facility2</td>
<td>change2</td>
</tr>
<tr>
<td>3</td>
<td>name3</td>
<td>field3</td>
<td>facility3</td>
<td>change3</td>
</tr>
<tr>
<td>4</td>
<td>name4</td>
<td>field4</td>
<td>facility4</td>
<td>change4</td>
</tr>
<tr>
<td>5</td>
<td>name5</td>
<td>field5</td>
<td>facility5</td>
<td>change5</td>
</tr>
<tr>
<td>6</td>
<td>name6</td>
<td>field6</td>
<td>facility6</td>
<td>change6</td>
</tr>
<tr>
<td>7</td>
<td>name7</td>
<td>field7</td>
<td>facility7</td>
<td>change7</td>
</tr>
<tr>
<td>8</td>
<td>name8</td>
<td>field8</td>
<td>facility8</td>
<td>change8</td>
</tr>
<tr>
<td>9</td>
<td>name9</td>
<td>field9</td>
<td>facility9</td>
<td>change9</td>
</tr>
<tr>
<td>10</td>
<td>name10</td>
<td>field10</td>
<td>facility10</td>
<td>change10</td>
</tr>
<tr>
<td>11</td>
<td>name11</td>
<td>field11</td>
<td>facility11</td>
<td>change11</td>
</tr>
<tr>
<td>12</td>
<td>name12</td>
<td>field12</td>
<td>facility12</td>
<td>change12</td>
</tr>
<tr>
<td>13</td>
<td>name13</td>
<td>field13</td>
<td>facility13</td>
<td>change13</td>
</tr>
<tr>
<td>14</td>
<td>name14</td>
<td>field14</td>
<td>facility14</td>
<td>change14</td>
</tr>
<tr>
<td>15</td>
<td>name15</td>
<td>field15</td>
<td>facility15</td>
<td>change15</td>
</tr>
</tbody>
</table>
Try this working demo. Below code:
table {
display: flex;
flex-flow: column;
height: 100%;
width: 100%;
border-collapse: separate;
border-spacing: 0 1px;
}
table thead {
flex: 0 0 auto;
width: calc(100% - 0.9em);
}
table tbody {
flex: 1 1 auto;
display: block;
overflow-y: scroll;
}
table tbody tr {
width: 100%;
}
table thead,
table tbody tr {
display: table;
table-layout: fixed;
}
tbody td,
thead th {
border-right: 1px solid transparent;
vertical-align: middle;
}
thead th {
height: 35px;
font-size: 16px;
text-align: left;
text-transform: uppercase;
}
tbody td {
text-align: left;
height: 30px;
background: #d5d5d5;
}
.table-cont {
width: 100%;
height: 350px;
}
<div class="table-cont">
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>field</th>
<th>facility</th>
<th>change</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>name1</td>
<td>field1</td>
<td>facility1</td>
<td>change1</td>
</tr>
<tr>
<td>2</td>
<td>name2</td>
<td>field2</td>
<td>facility2</td>
<td>change2</td>
</tr>
<tr>
<td>3</td>
<td>name3</td>
<td>field3</td>
<td>facility3</td>
<td>change3</td>
</tr>
<tr>
<td>4</td>
<td>name4</td>
<td>field4</td>
<td>facility4</td>
<td>change4</td>
</tr>
<tr>
<td>5</td>
<td>name5</td>
<td>field5</td>
<td>facility5</td>
<td>change5</td>
</tr>
<tr>
<td>6</td>
<td>name6</td>
<td>field6</td>
<td>facility6</td>
<td>change6</td>
</tr>
<tr>
<td>7</td>
<td>name7</td>
<td>field7</td>
<td>facility7</td>
<td>change7</td>
</tr>
<tr>
<td>8</td>
<td>name8</td>
<td>field8</td>
<td>facility8</td>
<td>change8</td>
</tr>
<tr>
<td>9</td>
<td>name9</td>
<td>field9</td>
<td>facility9</td>
<td>change9</td>
</tr>
<tr>
<td>10</td>
<td>name10</td>
<td>field10</td>
<td>facility10</td>
<td>change10</td>
</tr>
<tr>
<td>11</td>
<td>name11</td>
<td>field11</td>
<td>facility11</td>
<td>change11</td>
</tr>
<tr>
<td>12</td>
<td>name12</td>
<td>field12</td>
<td>facility12</td>
<td>change12</td>
</tr>
<tr>
<td>13</td>
<td>name13</td>
<td>field13</td>
<td>facility13</td>
<td>change13</td>
</tr>
<tr>
<td>14</td>
<td>name14</td>
<td>field14</td>
<td>facility14</td>
<td>change14</td>
</tr>
<tr>
<td>15</td>
<td>name15</td>
<td>field15</td>
<td>facility15</td>
<td>change15</td>
</tr>
</tbody>
</table>
</div>
I have such table: http://jsfiddle.net/jDTTx/
I can't understand how to split cell with text 1 into 2 horizontal cells. Could you help me with this?
You will want to set the rowspan for all of the cells in the row above it to 2, and leave the row span for the two cells which you would like to appear split as 1.
See it in action: http://jsfiddle.net/jDTTx/6/
<table border="1" style="border: 2px solid black; width: 50%; margin: 0 auto; text-align: center; font-weight: bold" cellpadding="0" cellspacing="0">
<thead style="background-color: gray; color: white">
<tr>
<td>№</td>
<td>Час</td>
<td>АУД. 402</td>
<td>АУД. 402<sup>A</sup></td>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">1</td>
<td rowspan="2">8<sup><u>00</u></sup> - 9<sup><u>20</u></sup></td>
<td>1a</td>
<td rowspan="2"></td>
</tr>
<tr>
<td>1b</td>
</tr>
<tr>
<td>2</td>
<td>9<sup><u>35</u></sup> - 10<sup><u>55</u></sup></td>
<td>6</td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>11<sup><u>15</u></sup> - 12<sup><u>35</u></sup></td>
<td></td>
<td>7</td>
</tr>
</tbody>
</table>
Place this in your cell:
<div style="border-bottom:solid 1px black">1a</div><div>1b</div>
http://jsfiddle.net/jDTTx/7/