HTML question

Shoddy

Veteran X
I don't know crap about presentation, but I need to expand some CSS classes into inline styles. In some cases there's already a style attribute, and I'm wondering if it's valid to add a second style attribute to the same element. In other words, is it valid to have <table style="some stuff here" style="other stuff here">? (I get that it can be <table style="some stuff here; other stuff here">, but that will be more complicated to produce.)
 
tables are only obsolete for layouts (obviously) but remain the best option for grid displays.

view source modern sites if you dont believe me
 
As already mentioned, you have to do <table style="stuff1; stuff2">. Things could break if you try <table style="stuff1" style="stuff2">

Not that hard. Just build the styles in a string beforehand. So an example for PHP would be (may not be precisely correct syntax wise):

$myStyle = "";
if (condition1) {
myStyle = "width:100px;";
}
if (condition2) {
myStyle += "padding:10px;";
}

Then when building the tag, <table style="<?php echo myStyle ?>">

Or javascript it's even easier.
myElement.style.padding = "10px";
myElement.style.width = "100px";
 
You guys laugh, but tables with inline styling are still in strong use.
Where?
HTML email campaigns. :(

I don't know if it will break for you to put all that styling in the line of your table tags <table>, but I do know you can have as many as you want in your td tags. <td>
 
Code:
<table style="background-color:#000;font-size:.0825em;color:#fff">

Sadly, with how fucked up Outlook's renderer is, inline styles are going to be around for a while. Also keep in mind that some things (like background images) aren't loaded in many online email viewers (like Gmail). If you're doing this for emailers, you might want to google what the major email clients will render.
 
Thanks for the suggestions. I'm loading a hundred thousandish HTML snippets into a database where they'll be served inside an app that doesn't have a compatible stylesheet, so that's why I need to put the styles inline.
 
Back
Top