HTML Question - Need odd table columns highlighted only - html

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>

Related

Hide and show table inside table when check box is checked in pure css

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>

HTML <table> tag, can't see any cell line

I'm a person who just started to learn coding through a basic HTML book.
Speaking the problem i faced directly,
I can't see the cell line on the brower without knowing why i can't see,
because I just copied the code which wrote on the book i studied on my code editor.
As I known, if I write the <table>code , there should be a cell line on the brower,
but I wasn't able to see that there...
If there is anyone who can explain to me, Please help me..
Thanks
Here is the all code.
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<td>Jake</td>
<td>24</td>
<td>Korea</td>
</tr>
<tr>
<td>Jane</td>
<td>24</td>
<td>Korea</td>
</tr>
</tbody>
</table>
Image:
There are cells & rows but can't see because there is no border for them.
You Can Style Your Table with CSS or put just <table border="1">
Snippet: Styled Table
.table {
width: 100%;
margin-bottom: 1rem;
background-color: transparent;
border: 1px solid #dee2e6
}
.table td,
.table th {
padding: .75rem;
vertical-align: top;
border-top: 1px solid #dee2e6
}
.table thead th {
vertical-align: bottom;
border-bottom: 2px solid #dee2e6
}
.table tbody+tbody {
border-top: 2px solid #dee2e6
}
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<td>Jake</td>
<td>24</td>
<td>Korea</td>
</tr>
<tr>
<td>Jane</td>
<td>24</td>
<td>Korea</td>
</tr>
</tbody>
</table>

Adding continuous border to only header and footer of table

I would like a table where some cells have broken borders and others have continuous borders. For example, here is the html for a four column, 12 row table:
<table>
<thead>
<tr class="header">
<th id="blank_cell"></th> <!-- blank -->
<th>first_c</th>
<th>second_c</th>
<th>third_c</th>
</tr>
</thead>
<tbody>
<tr>
<th>row one</th>
<td>1,1</td>
<td>1,2</td>
<td>1,3</td>
</tr>
<tr>
<th>row two</th>
<td>2,1</td>
<td>2,2</td>
<td>2,3</td>
</tr>
<tr>
<th>row three</th>
<td>3,1,</td>
<td>3,2</td>
<td>3,3</td>
</tr>
<tr>
<th>row four</th>
<td>4,1</td>
<td>4,2</td>
<td>4,3</td>
</tr>
<tr>
<th>row five</th>
<td>5,1</td>
<td>5,2</td>
<td>5,3</td>
</tr>
<tr>
<th>row six</th>
<td>6,1</td>
<td>6,2</td>
<td>6,3</td>
</tr>
<tr>
<th>row seven</th>
<td>7,1</td>
<td>7,2</td>
<td>7,3</td>
</tr>
<tr>
<th>row eight</th>
<td>8,1</td>
<td>8,2</td>
<td>8,3</td>
</tr>
<tr>
<th>row nine</th>
<td>9,1</td>
<td>9,2</td>
<td>9,3</td>
</tr>
<tr>
<th>row ten</th>
<td>10,1</td>
<td>10,2</td>
<td>10,3</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>End</th>
<td>e_one</td>
<td>e_two</td>
<td>e_three</td>
</tr>
</tfoot>
</table>
I would like the thead cells to have a continuous border along the bottom (except for the first, blank cell), whilst maintaining a broken border on the other rows.
Here is some CSS, it creates broken borders along the bottom of the rows (except the leftmost cells of each row).
body {
font-family:Arial,Verdana,sans-serif;
color:#111111;
}
table {
width:450px;
}
td,th {
padding:7px 10px 10px 10px;
}
thead th {
border-bottom:4px solid #111111;
}
tbody th {
border-left:2px solid #111111;
border-right:4px solid #111111;
}
tbody td {
border-bottom:2px solid #111111;
}
th {
text-transform:uppercase;
letter-spacing:0.1em;
word-spacing:0.3em;
text-align:left;
}
#blank_cell {
border:none;
}
tr:hover {
background-color:#c3e6e5;
}
I want the very first row - the header row - to have a continuous, unbroken line, whereas I want the others to remain as they are (i.e. broken). All I can find, so far, is styling that is applied to the whole table: for example, I can't seem to collapse borders or set zero spacing on just the cells in the thead part of the table. So if I make the borders continuous, it is applied to the entire table.
You'll probably have to put it in two different tables, the first containing the content of your tr.header, with cellspacing="0" and the second with the default value. However, that means that you'll have to add CSS to keep the width's consistent, and that may be a problem depending on what you are putting into the table(s). If that isn't a problem, here is the code with all columns set to 25% width:
(and a JSFiddle)
<body>
<table cellspacing="0">
<thead>
<tr class="header">
<th id="blank_cell"></th> <!-- blank -->
<th>first_c</th>
<th>second_c</th>
<th>third_c</th>
</tr>
</thead>
</table>
<table>
<tbody>
<tr>
<th>row one</th>
<td>1,1</td>
<td>1,2</td>
<td>1,3</td>
</tr>
<tr>
<th>row two</th>
<td>2,1</td>
<td>2,2</td>
<td>2,3</td>
</tr>
<tr>
<th>row three</th>
<td>3,1,</td>
<td>3,2</td>
<td>3,3</td>
</tr>
<tr>
<th>row four</th>
<td>4,1</td>
<td>4,2</td>
<td>4,3</td>
</tr>
<tr>
<th>row five</th>
<td>5,1</td>
<td>5,2</td>
<td>5,3</td>
</tr>
<tr>
<th>row six</th>
<td>6,1</td>
<td>6,2</td>
<td>6,3</td>
</tr>
<tr>
<th>row seven</th>
<td>7,1</td>
<td>7,2</td>
<td>7,3</td>
</tr>
<tr>
<th>row eight</th>
<td>8,1</td>
<td>8,2</td>
<td>8,3</td>
</tr>
<tr>
<th>row nine</th>
<td>9,1</td>
<td>9,2</td>
<td>9,3</td>
</tr>
<tr>
<th>row ten</th>
<td>10,1</td>
<td>10,2</td>
<td>10,3</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>End</th>
<td>e_one</td>
<td>e_two</td>
<td>e_three</td>
</tr>
</tfoot>
</table>
</body>
body {
font-family:Arial,Verdana,sans-serif;
color:#111111;
}
table {
width:450px;
}
td,th {
padding:7px 10px 10px 10px;
}
thead th {
border-bottom:4px solid #111111;
}
tbody th {
border-left:2px solid #111111;
border-right:4px solid #111111;
}
tbody td {
border-bottom:2px solid #111111;
width: 25%;
}
th {
text-transform:uppercase;
letter-spacing:0.1em;
word-spacing:0.3em;
text-align:left;
width: 25%;
}
#blank_cell {
border:none;
}
tr:hover {
background-color:#c3e6e5;
}

HTML/CSS code for creating a Table

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

Select first column of table having rowspan

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.