How do I target a table that is buried under some divs? - html

I have a table that I'm trying to target the 5th row using CSS. It is buried under 4 divs.
What is the best way to target the table? It uses a class that is duplicated many times throughout the website on many other table but I only wish to target this table which I have added a class of .q4 to:
Basically I'm trying to change the bottom border of a row within the table which is nested in a div within a div, within a div, within a div. The full html is below:
<div class="mobile-league-table q4">
<div class="sportspress">
<div class"sp-template sp-template-league-table">
<h4 class="sp-table-caption">UAE Division 1</h4>
<div class="sp-table-wrapper">
<div class="sp-scrollable-table-wrapper">
<table class="sp-league-table sp-data-table sp-scrollable-table" data-sp-rows="10">
<thead>
<tr>
<th class="data-rank">Pos</th>
<th class="data-name">Team</th>
<th class="data-p">P</th>
<th class="data-w">W</th>
<th class="data-l">L</th>
<th class="data-d">D</th>
<th class="data-pf">PF</th>
<th class="data-pa">PA</th>
<th class="data-pd">PD</th>
<th class="data-bp">BP</th>
<th class="data-pts">Pts</th>
<th class="data-form">Form</th>
</tr>
</thead>
<tbody>
<tr class="odd sp-row-no-0">…</tr>
<tr class="even sp-row-no-1">…</tr>
<tr class="odd sp-row-no-2">…</tr>
<tr class="even sp-row-no-3">…</tr>
<tr class="odd sp-row-no-4">…</tr>
<tr class="even sp-row-no-5">…</tr>
<tr class="odd sp-row-no-6">…</tr>
<tr class="even sp-row-no-7">…</tr>
<tr class="odd sp-row-no-8">…</tr>
<tr class="even sp-row-no-9">…</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
Thanks

Since the table inside the q4 div is the only one we can target it quite simply
.q4 table tbody tr:nth-child(your number here) td {
border-bottom: 1px solid black;
}
td {
padding:.25em;
}
.q4 table tbody tr:nth-child(3) td {
border-bottom: 1px solid black;
}
<div class="mobile-league-table q4">
<div class="sportspress">
<div class"sp-template sp-template-league-table">
<h4 class="sp-table-caption">UAE Division 1</h4>
<div class="sp-table-wrapper">
<div class="sp-scrollable-table-wrapper">
<table
class="sp-league-table sp-data-table sp-scrollable-table"
data-sp-rows="10"
>
<thead>
<tr>
<th class="data-rank">Pos</th>
<th class="data-name">Team</th>
<th class="data-p">P</th>
<th class="data-w">W</th>
<th class="data-l">L</th>
<th class="data-d">D</th>
<th class="data-pf">PF</th>
<th class="data-pa">PA</th>
<th class="data-pd">PD</th>
<th class="data-bp">BP</th>
<th class="data-pts">Pts</th>
<th class="data-form">Form</th>
</tr>
</thead>
<tbody>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
<td>Item 5</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
<td>Item 5</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
<td>Item 5</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
<td>Item 5</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
<td>Item 5</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>

Wordpress? Yikes.
Your best bet is to do some DOM manipulations after the HTML loads. I suggest using jquery. But if you can't import jquery into your project. You can still of course achieve this with javascript.
var x = document.getElementsByClassName('.sp-row-no-4');
x[0].innerHTML = "Hello World!";
getElementsByClassName() returns an array even if only one element is found via that class name. Hope that helps.

Related

In a table with multiple thead how to make repeat last thead on a page break

I have a HTML question:
If I have a table with multiple thead, on printing this page, the repetition on top of next page is first thead and not the last one.
Example:
<table>
<thead>
<tr>
<th>TH 1</th>
<th>TH 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>TD 1</td>
<td>TD 2</td>
</tr>
<tr>
<td>TD 1</td>
<td>TD 2</td>
</tr>
<tr>
<td>TD 1</td>
<td>TD 2</td>
</tr>
<tr>
<td>TD 1</td>
<td>TD 2</td>
</tr>
</tbody>
<thead>
<tr>
<th>TH 3</th>
<th>TH 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>TD 1</td>
<td>TD 2</td>
</tr>
<tr>
<td>TD 1</td>
<td>TD 2</td>
</tr>
<tr>
<td>TD 1</td>
<td>TD 2</td>
</tr>
<tr>
<td>TD 1</td>
<td>TD 2</td>
</tr>
</tbody>
The second-page header shows TH1 and TH2 instead of TH3 and TH4 during print preview.
Is there a way to print TH3 and TH4?

Change row background in HTML table depending on the value of the first column

This is my part of a table (with a number of rows that I don't know before I generate the table) that an external script creates:
<table id='testTable'><thead>
<tr>
<th align="center">Header 1</th>
<th align="center">Header 2</th>
<th align="center">Header 3</th>
<th align="center">Header 4</th>
<th align="center">Header 5</th>
<th align="center">Header 6</th>
<th align="center">Header 7</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">AAAA</td>
<td align="center">Field 1</td>
<td align="center">Field 2</td>
<td align="center">Field 3</td>
<td align="center">Field 4</td>
<td align="center">Field 5</td>
<td align="center">Field 1</td>
</tr>
<tr>
<td align="center">AAAA</td>
<td align="center">Field 1</td>
<td align="center">Field 2</td>
<td align="center">Field 3</td>
<td align="center">Field 4</td>
<td align="center">Field 5</td>
<td align="center">Field 1</td>
</tr>
<tr>
<td align="center">BBBB</td>
<td align="center">Field 1</td>
<td align="center">Field 2</td>
<td align="center">Field 3</td>
<td align="center">Field 4</td>
<td align="center">Field 5</td>
<td align="center">Field 1</td>
</tr>
<tr>
<td align="center">BBBB</td>
<td align="center">Field 1</td>
<td align="center">Field 2</td>
<td align="center">Field 3</td>
<td align="center">Field 4</td>
<td align="center">Field 5</td>
<td align="center">Field 1</td>
</tr>
<tr>
<td align="center">CCCC</td>
<td align="center">Field 1</td>
<td align="center">Field 2</td>
<td align="center">Field 3</td>
<td align="center">Field 4</td>
<td align="center">Field 5</td>
<td align="center">Field 1</td>
</tr>
I would like to change the background colors for alternate rows using 2 colors (grey and white, for example) considering the value of the first as the key. In the data above, it would be something like:
1st row --> white
2nd row --> grey
3rd row --> grey (because the key is still "BBBB")
4th row --> white
I checked another example but I was not able to use it, so it would be great to have step-by-step indications to edit the html or the CSS that I use to style the table (if necessary, I can post the content of the CSS too).

Creating HTML Table using CSS efffects [duplicate]

This question already has answers here:
How do you use colspan and rowspan in HTML tables?
(11 answers)
Closed 5 years ago.
I'm developing a webpage where I want to insert a table as seen in the image. I know how to use HTML tables, but I'm confused of creating this. I tried a lot to do this, but they are not working as I want. Please If some one could give me a guidance to develop this table I really appreciate it.
<table class="table table-bordered table-responsive" style="border-collapse: collapse; text-align: center; float: right;" border="1">
<tbody>
<tr>
<td></td>
<td style="text-align: center;" colspan="2">Table Data</td>
</tr>
<tr>
<th>Type </th>
<th>Orders<br />Phone/Fax/Email/Post</th>
<th>Number</th>
</tr>
</tbody>
<tbody>
<tr>
<td>Type 1</td>
<td>Order 1</td>
<td>Num 1</td>
</tr>
<tr>
<td>Type 2</td>
<td>Order 2</td>
<td>Num 2</td>
</tr>
<tr>
<td>Type 3</td>
<td>Order 3</td>
<td>Num 3</td>
</tr>
<tr>
<td>Type 4</td>
<td>Order 4</td>
<td>Num 4</td>
</tr>
<tr>
<td>Type 5</td>
<td>Order 5</td>
<td>Num 5</td>
</tr>
</tbody>
</table>
This does not give my desired output
File
Save as
choose filename
change file type to HTML Page
inspect HTML
If you want to handcraft this table have a look at colspan and rowspan or this SO question

border-collapse using HTML attribute

Is there an HTML attribute available equivalent to the CSS property border-collapse: collapse;?
I am trying to achieve the same 1px border with HTML only, and not using css.
table{
border-collapse: collapse;
}
<table border="1px" cellpadding="3">
<tr>
<td>Row 1</td>
<td>Row 1</td>
<td>Row 1</td>
</tr>
<tr>
<td>Row 2</td>
<td>Row 2</td>
<td>Row 2</td>
</tr>
</table>
You could try cellspacing.
<table border="1px" cellspacing="0" cellpadding="3">
<tr>
<td>Row 1</td>
<td>Row 1</td>
<td>Row 1</td>
</tr>
<tr>
<td>Row 2</td>
<td>Row 2</td>
<td>Row 2</td>
</tr>
</table>
Note: cellspacing doesn't overlap borders of adjacent cells, which CSS property does.
You can use cellspacing or cellpadding but it's deprecated in HTML5
i don't understand why you want to stop using CSS because that is what css do
you can use boostrap the css is included inside.
for more info go to w3chools
<div class="container">
<h2>Basic Table</h2>
<p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary#example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july#example.com</td>
</tr>
</tbody>
</table>
</div>

HTML Table vertically rather than horizontally?

I've got this table, and in this table are 4 columns, like this:
Column1|Column2|Column3|Column4|
data 1 data 2 data 3 data 4
But how do I get it like this?
Column1| data 1
Column2| data 2
Column3| data 3
Column4| data 4
This is my code:
<table>
<tr>
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
<th>Column4</th>
</tr>
</table>
Any ideas? Is it even possible?
Like this:
<table>
<tr>
<th>Column1</th>
<td>Data 1</td>
</tr>
<tr>
<th>Column2</th>
<td>Data 2</td>
</tr>
<tr>
<th>Column3</th>
<td>Data 3</td>
</tr>
<tr>
<th>Column4</th>
<td>Data 4</td>
</tr>
</table>
You put the th in the table rows
<table>
<tbody>
<tr>
<th>Column 1</th>
<td>Data 1</td>
</tr>
<tr>
<th>Column 2</th>
<td>Data 2</td>
</tr>
</tbody>
</table>
<table>
<tr>
<th>Column 1</th>
<td>Data 1</td>
</tr>
<tr>
<th>Column 2</th>
<td>Data 2</td>
</tr>
<tr>
<th>Column 3</th>
<td>Data 3</td>
</tr>
<tr>
<th>Column 4</th>
<td>Data 4</td>
</tr>
</table>
Maybe scope attribute can help you?
<table>
<tr scope="row">
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
<th>Column4</th>
</tr>
<tr>
<td>Some content</td>
<td>Some content</td>
<td>Some content</td>
<td>Some content</td>
</tr>
</table>
Also here, you get another solution by CSS.
you can use below pattern But i'll suggest you to use css tables : Page layout, Divs instead of Tables
<table>
<tr>
<th>Column1</th><td>data 1</td>
</tr>
<tr>
<th>Column1</th><td>data 1</td>
</tr>
<tr>
<th>Column1</th><td>data 1</td>
</tr>
<tr>
<th>Column1</th><td>data 1</td>
</tr>
</table>