I am currently working on this assignment for school. I have two issues I can't find the solution for.
HTML Validation gives me this error - A table row was 5 columns wide and exceeded the column count established by the first row (4).
From line 72, column 5; to line 72, column 9
As you can see on the table there is an extra column at the end that is very small. I am not sure how to eliminate that.
table {
margin: auto;
border: 1px solid #3399cc;
width: 90%;
border-collapse: collapse;
}
td, th {
padding: 5px;
border: 1px solid #3399cc;
}
td {
text-align: center;
}
.text {
text-align: left;
}
tr:nth-of-type(even) {
background-color: #f5fafc
}
<table>
<tr>
<th id="package-names">Package Name</th>
<th id="description">Description</th>
<th id="nights">Nights</th>
<th id="cost-per-person">Cost per Person</th>
</tr>
<tr>
<td headers="package-names">Weekend Escape</td>
<td headers="description" class="text">Two breakfasts, a trail map, a picnic snack</td>
<td headers="nights">2</td>
<td headers="cost-per-person">$450</td>
</tr>
<tr>
<td headers="package-names">Zen Retreat</td>
<td headers="description" class="text">Four breakfasts, a trail map, a pass for daily yoga</td>
<td headers="nights">4</td>
<td headers="cost-per-person">$600</td>
</tr>
<tr>
<td headers="package-names">Kayak Away</td>
<td headers="description" class="text">Two breakfasts, two hours of kayak rental daily, a trail map</td>
<td headers="nights">2</td>
<td headers="cost-per-person">$500<td>
</tr>
</table>
The error is in the very last td line:
<td headers="cost-per-person">$500<td>
The last tag has to be a closing tag: </td>instead of <td>
table {
margin: auto;
border: 1px solid #3399cc;
width: 90%;
border-collapse: collapse;
}
td, th {
padding: 5px;
border: 1px solid #3399cc;
}
td {
text-align: center;
}
.text {
text-align: left;
}
tr:nth-of-type(even) {
background-color: #f5fafc
}
<table>
<tr>
<th id="package-names">Package Name</th>
<th id="description">Description</th>
<th id="nights">Nights</th>
<th id="cost-per-person">Cost per Person</th>
</tr>
<tr>
<td headers="package-names">Weekend Escape</td>
<td headers="description" class="text">Two breakfasts, a trail map, a picnic snack</td>
<td headers="nights">2</td>
<td headers="cost-per-person">$450</td>
</tr>
<tr>
<td headers="package-names">Zen Retreat</td>
<td headers="description" class="text">Four breakfasts, a trail map, a pass for daily yoga</td>
<td headers="nights">4</td>
<td headers="cost-per-person">$600</td>
</tr>
<tr>
<td headers="package-names">Kayak Away</td>
<td headers="description" class="text">Two breakfasts, two hours of kayak rental daily, a trail map</td>
<td headers="nights">2</td>
<td headers="cost-per-person">$500</td>
</tr>
</table>
You're simply missing a slash in your closing <td> on the last row, which should look like so:
<td headers="cost-per-person">$500</td>
Fixed Version: http://codepen.io/alexgurrola/pen/EWrNEv?editors=1000
Related
table {
border: 2px solid #3399CC;
border-collapse: collapse;
}
td { padding: 0.5em;
border: 2px solid #3399CC;
}
th { padding: 0.5em;
border: 2px solid #3399CC;
}
td { text-align: center;
}
.text { text-align: left;
}
td:nth-child(odd) { background-color: #F5FAFC; }
<div id="special">
<h3>Yurt Packages</h3>
<p>A variety of luxury yurt packages are available. Choose a package below and contact us to begin your reservation. We’re happy to build a custom package just for you!</p>
<table>
<thead>
<tr>
<th>Package Name</th>
<th class="text">Description</th>
<th>Nights</th>
<th>Cost per Person</th>
</tr>
</thead>
<tbody>
<tr >
<td>Weekend Escape</td>
<td class="text">Two breakfasts, a trail map, and a picnic snack</td>
<td>2</td>
<td>$450</td>
</tr>
<tr>
<td>Zen Retreat</td>
<td class="text">Four breakfasts, a trail map, a picnic snack, and a pass for the daily sunrise Yoga session</td>
<td>4</td>
<td>$600</td>
</tr>
<tr>
<td>Kayak Away</td>
<td class="text">Two breakfasts, two hours of kayak rental daily, and a trail map</td>
<td>2</td>
<td>$500</td>
</tr>
</tbody>
</table>
</div>
What you see here is HTML and CSS code for a table, that is supposed to be white and blue.
INSTRUCTIONS ask that the ODD columns are BLUE, but instead everything has a blue background. I cannot figure it out :(
help appreciated, thanks!!!
Here is CSS that will get the job done at the table cell level. If you don't want the table header to have the blue and white colors, just remove the th selectors from the CSS.
th:nth-child(even), td:nth-child(even) {
background: white;
}
th:nth-child(odd), td:nth-child(odd) {
background: blue;
}
<table>
<thead>
<tr>
<th>Package Name</th>
<th class="text">Description</th>
<th>Nights</th>
<th>Cost per Person</th>
</tr>
</thead>
<tbody>
<tr>
<td>This is stesg</td>
<td>This is stesg</td>
<td>This is stesg</td>
<td>This is stesg</td>
</tr>
<tr>
<td>This is stesg</td>
<td>This is stesg</td>
<td>This is stesg</td>
<td>This is stesg</td>
</tr>
</tbody>
</table>
in your css add
tr:nth-child(odd){
backgound-color:blue;
}
Please check the code below. If you want the table header in a different color then you are nesting thead tr selectors and setting the background color from the CSS.
table {
border: 2px solid #3399cc;
border-collapse: collapse;
}
thead tr {
background-color: #140c12;
color: #fff;
}
th {
padding: 0.5em;
border: 2px solid #3399cc;
}
td {
padding: 0.5em;
border: 2px solid #3399cc;
text-align: center;
}
tbody tr:nth-child(odd) {
background-color: #eb7d4b;
}
.text {
text-align: left;
}
<div id="special">
<table>
<thead>
<tr>
<th>Package Name</th>
<th class="text">Description</th>
<th>Nights</th>
<th>Cost per Person</th>
</tr>
</thead>
<tbody>
<tr>
<td>Weekend Escape</td>
<td class="text">
Two breakfasts, a trail map, and a picnic snack
</td>
<td>2</td>
<td>$450</td>
</tr>
<tr>
<td>Zen Retreat</td>
<td class="text">
Four breakfasts, a trail map, a picnic snack, and a pass for the
daily sunrise Yoga session
</td>
<td>4</td>
<td>$600</td>
</tr>
<tr>
<td>Kayak Away</td>
<td class="text">
Two breakfasts, two hours of kayak rental daily, and a trail map
</td>
<td>2</td>
<td>$500</td>
</tr>
<tr>
<td>Kayak Away</td>
<td class="text">
Two breakfasts, two hours of kayak rental daily, and a trail map
</td>
<td>3</td>
<td>$800</td>
</tr>
</tbody>
</table>
</div>
I want to send mail with the below template from code. I am trying to hide and display the secondary table with the checkbox. I think I am stuck with the css selector. Is it possible to hide and show something with the checkbox. Important thing is I want to do it in only css , " NO JS " Here is the codepen edit link : https://codepen.io/rishisarma/pen/QWqyqXd?editors=1100
.box {
display:none;
}
<-- Here is the issue I think when I tried to hide and display the table it is not working.-->
input[id='trigger']:checked table.box{
display:block;
}
table {
font-family: "Trebuchet MS";
margin: 8px;
}
tr:nth-child(odd) {
background-color: #f7f7f7;
}
.rightalign {
text-align: right;
width: 125px;
}
th {
background-color: #e84f32;
padding: 8px;
color: white;
border: 1px solid #e0e0e0;
}
td {
padding: 8px;
border: 1px solid #e0e0e0;
}
<table>
<thead>
<tr>
<th colspan="9" style="width:100%;" id="head">Client Wise AttendenceReport (2021/12/05)</th>
</tr>
<tr>
<th></th>
<th>SRNO</th>
<th>Customer</th>
<th>Organizations</th>
<th>Attendees (2021/12/04)</th>
<th>Attendees (2021/12/05)</th>
<th>Txns (2021/12/04)</th>
<th>Txns (2021/12/05)</th>
<th>Inclination (%)</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="checkbox" id="trigger">
</td>
<td>1</td>
<td>TSTS</td>
<td>33 (0%)</td>
<td>1605382</td>
<td>1605563 (0.01)</td>
<td>139313</td>
<td>20726</td>
<td>-85.12</td>
</tr>
<tr>
<td colspan="9">
<table class = "box">
<tr>
<td colspan="5" style="background-color: #e84f32; padding: 8px; color:white; text-align:center">Organisation Wise Transaction Report On 05-Dec- 2021</td>
</tr>
<tr>
<th>Slno</th>
<th>Organisation</th>
<th>Registered Users</th>
<th>Present Today</th>
<th>Percent(%)</th>
</tr>
<tr>
<td>1</td>
<td>TSTSATTENDANCE</td>
<td class="rightalign">294</td>
<td class="rightalign">3</td>
<td class="rightalign">1%</td>
</tr>
</table>
</td>
</tr>
<tr>
<td></td>
<td>2</td>
<td>GVK</td>
<td>2 (0%)</td>
<td>1329</td>
<td>1329 (0)</td>
<td>681</td>
<td>686</td>
<td>0.73</td>
</tr>
<tr>
<td></td>
<td>3</td>
<td>SIL</td>
<td>33 (0%)</td>
<td>202240</td>
<td>203042 (0.4)</td>
<td>111348</td>
<td>7519</td>
<td>-93.25</td>
</tr>
</tbody>
</table>
I have a complicated set of table rows with colspans and rowspans all over the shop. All works fine except for the bottom row in Internet Explorer which forces it's height to be the same as the previous row, which is set to rowspan="2". How can I fix this?
Also, the layout needs to be a table because a PDF generator uses it and that requires tables. Ideally the HTML layout wouldn't change at all, but it can change if it needs to.
Below is the code. Look at it in Google Chrome to see how it should be displaying in IE.
.MhrPayslipDetail {
display: block;
font-family: sans-serif;
font-size: 16px;
padding: 20px 60px;
text-align: center;
}
.MhrPayslipDetail-payslip {
background-color: #fff;
border-collapse: separate;
border-spacing: 10px;
width: 100%;
}
.MhrPayslipDetail-label {
background-color: #c1c1c1;
border: 1px solid #c1c1c1;
border-radius: 5px;
font-weight: bold;
padding: 4px;
text-align: left;
vertical-align: middle;
}
.MhrPayslipDetail-cell,
.MhrPayslipDetail-cellRight {
background-color: #fff;
border: 1px solid #c1c1c1;
border-radius: 5px;
padding: 4px;
text-align: left;
vertical-align: middle;
}
.MhrPayslipDetail-cellRight {
text-align: right;
}
.MhrPayslipDetail-list {
border: 0;
border-collapse: collapse;
width: 100%;
}
.MhrPayslipDetail-listCell,
.MhrPayslipDetail-listLabel,
.MhrPayslipDetail-listCellHeader {
border: 0;
padding: 1px;
text-align: left;
vertical-align: middle;
}
.MhrPayslipDetail-listCellRight,
.MhrPayslipDetail-listCellHeaderRight {
border: 0;
padding: 1px;
text-align: right;
vertical-align: middle;
}
.MhrPayslipDetail-listLabel,
.MhrPayslipDetail-listCellHeader {
font-weight: bold;
width: 50%;
}
.MhrPayslipDetail-details {
font-size: .9em;
}
.MhrPayslipDetail-paymentsDetails,
.MhrPayslipDetail-deductionsDetails {
height: 21em;
vertical-align: top;
}
.MhrPayslipDetail-thisPeriodDetails,
.MhrPayslipDetail-yearToDateDetails {
height: 10em;
vertical-align: top;
}
<div class="MhrPayslipDetail">
<table class="MhrPayslipDetail-payslip">
<tbody>
<tr>
<td colspan="3" rowspan="3" class="MhrPayslipDetail-cell MhrPayslipDetail-paymentsDetails">
<table class="MhrPayslipDetail-details MhrPayslipDetail-list">
<thead>
<tr>
<th class="MhrPayslipDetail-listCellHeader">Description</th>
<th class="MhrPayslipDetail-listCellHeaderRight">U/T</th>
<th class="MhrPayslipDetail-listCellHeaderRight">Rate</th>
<th class="MhrPayslipDetail-listCellHeaderRight">Cash</th>
</tr>
</thead>
<tbody>
<tr>
<td class="MhrPayslipDetail-listCell">Test Basic Pay</td>
<td class="MhrPayslipDetail-listCellRight"></td>
<td class="MhrPayslipDetail-listCellRight"></td>
<td class="MhrPayslipDetail-listCellRight">200.00</td>
</tr>
</tbody>
</table>
</td>
<td colspan="2" rowspan="3" class="MhrPayslipDetail-cell MhrPayslipDetail-deductionsDetails">
<table class="MhrPayslipDetail-details MhrPayslipDetail-list">
<thead>
<tr>
<th class="MhrPayslipDetail-listCellHeader">Description</th>
<th class="MhrPayslipDetail-listCellHeaderRight">Cash</th>
</tr>
</thead>
<tbody>
<tr>
<td class="MhrPayslipDetail-listCell">Tax</td>
<td class="MhrPayslipDetail-listCellRight">25.40</td>
</tr>
<tr>
<td class="MhrPayslipDetail-listCell">NI</td>
<td class="MhrPayslipDetail-listCellRight">24.00</td>
</tr>
</tbody>
</table>
</td>
<td colspan="2" class="MhrPayslipDetail-cell MhrPayslipDetail-thisPeriodDetails">
<table class="MhrPayslipDetail-details MhrPayslipDetail-list">
<thead>
<tr>
<th class="MhrPayslipDetail-listCellHeader">Description</th>
<th class="MhrPayslipDetail-listCellHeaderRight">Cash</th>
</tr>
</thead>
<tbody>
<tr>
<td class="MhrPayslipDetail-listCell">Taxable Pay</td>
<td class="MhrPayslipDetail-listCellRight">200.00</td>
</tr>
<tr>
<td class="MhrPayslipDetail-listCell">Employers National Insurance</td>
<td class="MhrPayslipDetail-listCellRight">27.60</td>
</tr>
<tr>
<td class="MhrPayslipDetail-listCell">Niable Pay</td>
<td class="MhrPayslipDetail-listCellRight">200.00</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<th colspan="2" class="MhrPayslipDetail-label">Year-to-date</th>
</tr>
<tr>
<td colspan="2" rowspan="2" class="MhrPayslipDetail-cell MhrPayslipDetail-yearToDateDetails">
<table class="MhrPayslipDetail-details MhrPayslipDetail-list">
<tbody>
<tr>
<td class="MhrPayslipDetail-listCell">Taxable Pay</td>
<td class="MhrPayslipDetail-listCellRight">7,200.00</td>
</tr>
<tr>
<td class="MhrPayslipDetail-listCell">NI</td>
<td class="MhrPayslipDetail-listCellRight">622.08</td>
</tr>
<tr>
<td class="MhrPayslipDetail-listCell">Tax</td>
<td class="MhrPayslipDetail-listCellRight">25.40</td>
</tr>
<tr>
<td class="MhrPayslipDetail-listCell">Niable Pay</td>
<td class="MhrPayslipDetail-listCellRight">7,200.00</td>
</tr>
<tr>
<td class="MhrPayslipDetail-listCell">Employers National Insurance</td>
<td class="MhrPayslipDetail-listCellRight">713.73</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<th class="MhrPayslipDetail-label">Payments</th>
<td class="MhrPayslipDetail-cellRight" colspan="2">200.00</td>
<th class="MhrPayslipDetail-label">Deductions</th>
<td class="MhrPayslipDetail-cellRight">49.40</td>
</tr>
</tbody>
</table>
</div>
UPDATE
Since submitting this question I have tried using sub-tables to separate out the columns, however I found that when I did that I wasn't able to get them to line up correctly due to border spacing and the PDF generator's lack of being able to use border-collapse:collapse;.
As an FYI, this is the PDF generator the system is using.
I have one table.
I would like to set different cell width for different rows.
For example, at the third row, I would like to set the EQUAL column width of 3rd and 4th column. No matter the 3rd column has text overflow.
original output:
expected output:
Is it possible to do so? Thanks you very much!
<style type="text/css"> .tg {border-collapse:collapse;border-spacing:0;border-color:#aabcfe;margin:0px auto;} .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#aabcfe;color:#669;background-color:#e8edff;} .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#aabcfe;color:#039;background-color:#b9c9fe;} .tg .tg-s6z2{text-align:center} .tg .tg-vn4c{background-color:#D2E4FC} .tg .tg-0ord{text-align:right} .table {table-layout: fixed;} </style>
<table class="tg" table width="500"> <tr>
<th class="tg-s6z2" colspan="6">Results</th> </tr> <tr>
<td class="tg-vn4c" width="5%">No</td>
<td class="tg-vn4c" width="15%">Competition</td>
<td class="tg-vn4c" width="20%">John</td>
<td class="tg-vn4c" width="20%">Adam</td>
<td class="tg-vn4c" width="20%">Robert</td>
<td class="tg-vn4c" width="20%">Paul</td> </tr> <tr>
<td class="tg-031e">1</td>
<td class="tg-031e">Swimming</td>
<td class="tg-0ord" colspan="2">line1<br>line 2<br>line 3<br>12345678901234567890123451234567890<br><br></td>
<td class="tg-0ord" colspan="2">ABCD<br><br></td> </tr> </table>
To answer the question:
Technically, yes it is possible with tables using empty cells, colspans and manipulating borders. In fact, I made it.
Don't do this
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
border: solid 1px #000;
padding: 10px;
}
.noborder {
border: none;
border-top: solid 1px #000;
border-bottom: solid 1px #000;
}
.leftborder {
border-left: solid 1px #000
}
.rightborder {
border-right: solid 1px #000
}
<h1>Don't do this!</h1>
<table>
<tr>
<th>No</th>
<th>Comp</th>
<td>John</td>
<td class="noborder">Matthew</td>
<td class="noborder"></td>
<td>Mark</td>
<td>Luke</td>
</tr>
<tr>
<td>1</td>
<td>Swimming</td>
<td colspan="2" class="noborder">Details</td>
<td colspan="3" class="noborder leftborder rightborder">Details</td>
</tr>
</table>
Practically though, this is overly complex and impossible to maintain; it also defeats the purpose of a table.
Possible alternative
This is a possible idea, though it could still be difficult to maintain and I don't know exactly what you are trying to display.
Sticking with a table
Depending on what information you are trying to display, you could use a table for this with a different layout. The rowspans join the information relevant to each name.
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
border: solid 1px #000;
padding: 10px;
}
<table>
<thead>
<tr>
<th scope="col">No</th>
<th scope="col">Competition</th>
<th scope="col">Name</th>
<th scope="col">Details 1</th>
<th scope="col">Details 2</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row" rowspan="5">1</th>
<th scope="row" rowspan="5">Swimming</th>
<td>John</td>
<td rowspan="3">This info is relevant to John, Steven and Mark</td>
<td rowspan="2">This info is relevant to John and Steven</td>
</tr>
<tr>
<td>Steven</td>
</tr>
<tr>
<td>Mark</td>
<td rowspan="2">This info is relevant to Mark and Peter</td>
</tr>
<tr>
<td>Peter</td>
<td>The info is only relevant to Peter</td>
</tr>
</tbody>
</table>
you can use style sheet that sounds like hacks to this.. because doing this in table property isn't possible
see this jsfiddle
I have a table with rowspan in first cells of row. I want to select first cells. When I select first child, in some rows after rowspan, first child going to be cells that are not in first row.
How to select just first column of table?
Here is my JSFIDDLE http://jsfiddle.net/qw78pcud/
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
table{
font-size: 18px;
color: black;
}
table tr td:first-child{
color: red;
text-align: center;
}
<table>
<thead>
<tr>
<th>Country</th>
<th>Bank Name</th>
<th>SWIFT BIG</th>
<th>Currency</th>
</tr>
</thead>
<tbody>
<tr>
<td>USA</td>
<td>Deutsche Bank Trust Company Americas, New Your</td>
<td>BKTRUS33</td>
<td>USD</td>
</tr>
<tr>
<td>Germany</td>
<td>Deutsche Bank AG</td>
<td>DEUTDEFF</td>
<td>EUR</td>
</tr>
<tr>
<td rowspan="2">Austria</td>
<td rowspan="2">Raiffeisen Bank International AG</td>
<td rowspan="2">RZBAATWW</td>
<td>EUR</td>
</tr>
<tr><td>USD</td></tr>
<tr>
<td rowspan="5">Netherlands</td>
<td rowspan="5">Demir - Halk Bank (Nederland) N.V.</td>
<td rowspan="5">DHBNNL2R</td>
<td >EUR</td>
</tr>
<tr><td>USD</td></tr>
<tr><td>GBP</td></tr>
<tr><td>CHF</td></tr>
<tr><td>JPY</td></tr>
</tbody>
</table>
I used following selector but it selects last childs after rowspan as jsfiddle shows
table tr td:first-child{
color: red;
text-align: center;
}
Note: I can't set class or id to table elements. I need to access with css.
Edit: What can we do in This case? http://jsfiddle.net/qw78pcud/6
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
table{
font-size: 18px;
color: black;
}
table tr td:first-child:not(:only-child) {
color: red;
text-align: center;
}
<table>
<thead>
<tr>
<th>Country</th>
<th>Bank Name</th>
<th>SWIFT BIG</th>
<th>Currency</th>
</tr>
</thead>
<tbody>
<tr>
<td>USA</td>
<td>Deutsche Bank Trust Company Americas, New Your</td>
<td>BKTRUS33</td>
<td>USD</td>
</tr>
<tr>
<td>Germany</td>
<td>Deutsche Bank AG</td>
<td>DEUTDEFF</td>
<td>EUR</td>
</tr>
<tr>
<td rowspan="2">Austria</td>
<td rowspan="2">Raiffeisen Bank International AG</td>
<td rowspan="2">RZBAATWW</td>
<td>EUR</td>
</tr>
<tr><td>USD</td></tr>
<tr>
<td rowspan="5">Netherlands</td>
<td rowspan="5">Demir - Halk Bank (Nederland) N.V.</td>
<td rowspan="5">DHBNNL2R</td>
<td >EUR</td>
</tr>
<tr><td>USD</td></tr>
<tr><td>GBP</td></tr>
<tr><td>CHF</td></tr>
<tr><td>JPY</td></tr>
<tr>
<td rowspan="10">Russia</td>
<td rowspan="3">CB “Garanti Bank – Moscow” (ZAO)</td>
<td rowspan="3">GABMRUMM</td>
<td >EUR</td>
</tr>
<tr><td>USD</td></tr>
<tr><td>RUB</td></tr>
<tr>
<td rowspan="2">Sberbank of Russia </td>
<td rowspan="2">SABRRUMM</td>
<td>USD</td>
</tr>
<tr><td>RUB</td></tr>
<tr>
<td rowspan="3">JSCB “Yapi Kredi Bank Moscow" (CJSC)</td>
<td rowspan="3">YKBMRUMM</td>
<td>EUR</td>
</tr>
<tr><td>USD</td></tr>
<tr><td>RUB</td></tr>
<tr>
<td rowspan="2">ZAO Raiffeisenbank </td>
<td rowspan="2">RZBMRUMM</td>
<td>USD</td>
</tr>
<tr><td>RUB</td></tr>
</tbody>
</table>
You could achieve that by using a combination of :not() and :only-child pseudo-classes as follows:
Example Here
table tr td:first-child:not(:only-child) {
color: red;
text-align: center;
}
This would exclude the cells that are the only child of their parents - the rows.