PowerShell, HTML, and CSS

Status
Not open for further replies.

Utildayael

Ars Tribunus Angusticlavius
7,345
Bit of a mixed bag question.

Created a dataset in PowerShell saved to an array. I'm building an HTML table off it to use for an HTML-format email. Easy right?

Table works. Email works. My CSS styles all work EXCEPT one... nth-child.

Trying to get alternating row colors to work and for some reason I can't! Does not work in Chrome, IE11, or Outlook. :(


I've looked all over and my code for my <STYLE> tag seems to be sound... and everything ELSE in the tag works.. but this"

Code:
tr:nth-child(odd) {background-color: lightgray;}


It's like it is being ignored completely in my tables.

Any ideas?
 

Utildayael

Ars Tribunus Angusticlavius
7,345
Weird thing is, I expected Outlook to barf but not IE/Chrome.

So I'm testing your method Pont and having.. problems... The code looks fine but it doesn't seem to actually apply said code. Code snippet, its in an env I can't copy-paste from so paraphrasing.

Code:
<HTML>
<HEAD>

<STYLE>
TABLE { css stuff that actually works here }
TH { css stuff that actually works here }
TD { css stuff that actually works here }
.row0 { background-color: white; }
.row1 { background-color: lightgray; }
</STYLE>
</HEAD>

<BODY>

<TABLE>
<TH>Col Header 1</TH>
<TR class="row0"><TD>Some Data</TD></TR>
<TR class="row1"><TD>Some Other Data</TD></TR>
</TABLE>

</BODY>
</HTML>


Goofy deal. Gave it to a web dev buddy as well and he looked at it and goes "uh that all looks fine" ... :confused:
 

Caelestian

Ars Centurion
236
Subscriptor++
Weird thing is, I expected Outlook to barf but not IE/Chrome.

So I'm testing your method Pont and having.. problems... The code looks fine but it doesn't seem to actually apply said code. Code snippet, its in an env I can't copy-paste from so paraphrasing.

Code:
<HTML>
<HEAD>

<STYLE>
TABLE { css stuff that actually works here }
TH { css stuff that actually works here }
TD { css stuff that actually works here }
.row0 { background-color: white; }
.row1 { background-color: lightgray; }
</STYLE>
</HEAD>

<BODY>

<TABLE>
<TH>Col Header 1</TH>
<TR class="row0"><TD>Some Data</TD></TR>
<TR class="row1"><TD>Some Other Data</TD></TR>
</TABLE>

</BODY>
</HTML>


Goofy deal. Gave it to a web dev buddy as well and he looked at it and goes "uh that all looks fine" ... :confused:

TH is not a valid child of TABLE - Needs to be wrapped in a TR
 

Utildayael

Ars Tribunus Angusticlavius
7,345
Just for grins, does changing "lightgrey" to "#DDDDDD" make it work?

Edit: Also, what if you apply the class to the TD instead of the TR?

Ya did same with and without color "names" ... but your TD idea helped me catch the actual bug since that worked!


TH is not a valid child of TABLE - Needs to be wrapped in a TR

Good catch. Did not fix my problem but shows how rusty my HTML is. :)

As I was pasting my actual code for more troubleshooting I figured out the issue.

In my CSS I had defined TD as having a background color of white. When I tried to apply the TR row color it was being overwritten by the TD color!

This is also what was borking nth-child as once I removed the bg color from TD in CSS and put nth-child back in, works like a charm.

Appreciate the help. The PowerShell bit Pont posted is going in the toolbox for future use tho in case I run into something that doesn't play nice with nth-child. :)
 

Utildayael

Ars Tribunus Angusticlavius
7,345
nth-child won't work in emails. Email clients have extremely limited CSS support. In fact, gmail will strip any <style> tags out of the email before sending it to the browser/app. If you want good cross-client support you should do styling in-line in emails e.g., replace the class with style="color: #fff".

That's what I ended up doing after I realized that nth-child doesn't work in Outlook nor does any sort of class=.
 
Status
Not open for further replies.