Rowspan at the end of the table is working differently - html

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:

Related

How to make compressed html tables [closed]

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

show a border in table rows when there is not td

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.

Centering a column in a table

I am trying to center just certain columns in a table but I am having issues. I know in the past you would just simply apply inline styles to each TD but there has to be a better way.
Here is a simple example:
.centerText{
text-align:center;
}
<table border="1">
<col>
<col class="centerText">
<thead>
<tr>
<th>heading1</th>
<th>heading2</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
</tr>
</tbody>
</table>
With that class I am trying to center the text inside. I know applying css to the col will work for changing background color for the column and text color and such, but I am not sure how I would use it to center a column. I am assuming because I need to center the contents of the td and this is probably just centering the TD element itself; which is already 100 percent.
I understand I can just say apply the css to the 5th TD in this TR but that seems fragile.
Also, bonus points if you can show me how to change the width of a column this way. I used the width attribute for col but that is deprecated in html 5 (even though it is still currently supported.
Done, your class wasn't used anywhere
tr td:nth-child(2) {
text-align:center;
}
<table border="1">
<thead>
<tr>
<th>heading1</th>
<th>heading2</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td >2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
</tr>
</tbody>
</table>
I removed:
<col>
<col class="centerText">
and
.centerText{
text-align:center;
}
Because col doesn't mean anything and you didn't close the tags.
CSS
table {
border-collapse: collapse;
width: 100%;
}
td {
text-align: center
}
If you want to align your all td content to the center
add the centerText class to your table
<table class="centerText" border="1">
It's not completely clear what you want, but if you want to center the contents of a certain column, you can just use this CSS rule:
td:nth-child(2) {
text-align:center;
}
In this example it applies to the second column, but you could define that for any column. It works since the td are always children of a tr, so you can use the nth-child selector.
td:nth-child(2) {
text-align: center;
}
<table border="1">
<col>
<col class="centerText">
<thead>
<tr>
<th>heading1</th>
<th>heading2</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
</tr>
</tbody>
</table>

HTML: How to create a calendar view?

I am HTML/CSS beginner attempting to create calendar view very similar to Microsoft Outlook's design as shown below:
So far, I gotten the basic outline of the calendar with the following HTML/CSS:
<html>
<head>
<title>August, 2016</title>
</head>
<body>
<center><h1>August, 2016</h1></center>
<style>
table{
table-layout: fixed;
}
</style>
<table border="1" width="1250" height="800">
<tr>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thur</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<table>
<tr>
<td>1</td>
<td></td>
</tr>
<tr>
<td></td>
<td>
Claim Benefits<br>
Pick up groceries<br>
Iron the shirts<br>
+5 more...
</td>
</tr>
</table>
</td>
<td>2</td>
</tr>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</tr>
<td>3</td>
<td>4</td>
<td>
<table>
<tr>
<td>5</td>
<td></td>
</tr>
<tr>
<td></td>
<td>
Claim Benefits<br>
Pick up groceries<br>
Iron the shirts<br>
+5 more...
</td>
</tr>
</table>
</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</tr>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</tr>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</tr>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
</body>
</html>
Which produces:
I want to accomplish some of the same things Outlook does:
The day of the month number should be on the top left corner of the cell. I attempted to create this with a table inside the cell but it doesn't quite feel or look right. I am directly attempting to recreate Outlook's view and the way they setup the day number and reminders below it.
Each of the cells should maintain the same size while containing up to 4 hyperlinks. In the above code, the cells of the row containing hyperlinks become bigger than the cells of the other rows. I want to fix the cell size such that all cells are the same size whether they contain up to 4 hyperlinks or not.
Thanks for any helpful code or suggestions.
An easy way to position/style the calendar numbers separately from the content is to make them td pseudo-elements. You could set the content to something like attr(data-day) to have it dynamically display a number set in the HTML.
To make sure the cells have the same height, just specify a height in the CSS. Since you only want "up to 4 hyperlinks", you can just check what the height is for a cell with 4 links and then use that.
By the way, it looks like there are a lot of errors with the tr tags in your code, and I would recommend representing the listed elements inside an individual day as a list rather than as nested tables (the calendar is tabular data, but the contents of the day are a to-do list).
Here's a snippet that includes the recommended changes:
table {
table-layout: fixed;
width: 1250px;
height: 800px;
}
table td {
height: 100px;
position: relative;
}
table td:before {
content: attr(data-day);
display: block;
position: absolute;
top: 0;
left: 0;
background: yellow;
}
<center>
<h1>August, 2016</h1>
</center>
<table border="1">
<tr>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thur</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td data-day="1">
<ul>
<li>Claim Benefits</li>
<li>Pick up groceries</li>
<li>Iron the shirts</li>
<li>+5 more...</li>
</ul>
</td>
<td data-day="2"></td>
</tr>
<tr>
<td data-day="3"></td>
<td data-day="4"></td>
<td data-day="5"></td>
<td data-day="6"></td>
<td data-day="7"></td>
<td data-day="8"></td>
<td data-day="9"></td>
</tr>
<tr>
<td data-day="10"></td>
<td data-day="11"></td>
<td data-day="12">
<ul>
<li>Claim Benefits</li>
<li>Pick up groceries</li>
<li>Iron the shirts</li>
<li>+5 more...</li>
</ul>
</td>
<td data-day="13"></td>
<td data-day="14"></td>
<td data-day="15"></td>
<td data-day="16"></td>
</tr>
<tr>
<td data-day="17"></td>
<td data-day="18"></td>
<td data-day="19"></td>
<td data-day="20"></td>
<td data-day="21"></td>
<td data-day="22"></td>
<td data-day="23"></td>
</tr>
<tr>
<td data-day="24"></td>
<td data-day="25"></td>
<td data-day="26"></td>
<td data-day="27"></td>
<td data-day="28"></td>
<td data-day="29"></td>
<td data-day="30"></td>
</tr>
<tr>
<td data-day="31"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
I think You can add a flot:left; style to this month number, and maybe margin,padding:0;
I suggest to use min-height with the same value as height of all cells
First, you have not added any styling so you are leaving that up to the browser's defaults. Also, the center tag is deprecated. Use this instead:
h1 {text-align:center;}
For the table, you can add this to make the border appear like Outlooks' borders:
table, th, td {border-collapse: collapse;}
To style the table data remove the padding and margin. That should move the first td in the first tr to the top left corner.
Lastly, add a specific height to the row of each week. I would assign that tr a class of week and style with whatever height you want:
tr.week {height:200px;}

Html and tables

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/