Okay - the scenario: using inline styles in an html table, to make the table portable and entirely self-contained.
(So that the table can be used situations where you do not have access to the html page's header block -- as is the case, for example, with content management systems such as those used by Blogger, where you can insert html into the body of a blog post, but can't define a style block for a given page without opening a can of worms).
The challenge: define a mouseover event that changes the background colour of a table row.
This is a challenge because each table column has a different colour, and each cell defines its own colour. Yet inline styles take precedence over other styles, and an inline onmouseover
instruction seems not to work.
Solution 1.
Define inline styles for each cell, to make table portable.
Override inline style with <style>
block defined within body.
Where the only statement inside the style block is that implementing
the mouseover.
Note: it is necessary to use the !important
declaration in any mouseover style attribute, because otherwise it would not be able to claim precedence over the inline styles, and would have no effect.
<body>
<!-- style block defined in HTML body
to define CSS elements that could not be used inline.
!important declaration necessary
to override inline styles -->
<style type="text/css">
table tr:hover td
{
background-color: #0ABC1F !important;
}
</style>
<table>
<thead><tr><th scope="col">one</th>
<th scope="col">two</th>
<th scope="col">three</th></tr>
</thead>
<!-- define inline styles for each table cell
to make table portable -->
<tr>
<td style="background-color: #ABCDEF;color:#000000;"
>1000</td>
<td style="background-color: #FEDCBA;color:#000000;"
>W</td>
<td style="background-color: #ABABAB;color:#000000;"
>1</td>
</tr>
</body>
Solution 2.
Define classes for each cell, using CSS classes defined in style block.
Put style block within html body.
Put in style block all classes, as well as mouseover instruction.
<!-- define CSS style class for each table cell
in style block inside HTML body
to make table portable -->
<style type="text/css">
table tr:hover td
{
background-color: #0ABC1F !important;
}
.one { background-color: #ABCDEF;color:#000000; }
.two { background-color: #FEDCBA;color:#000000; }
.three { background-color: #ABABAB;color:#000000; }
</style>
<table>
<thead><tr><th scope="col">one</th>
<th scope="col">two</th>
<th scope="col">three</th></tr>
</thead>
<tr>
<td class="one">1000</td>
<td class="two">W</td>
<td class="three">1</td>
</tr>
Option 1 seems wiser because of what is said about the potential for <style>
blocks inside<body> blocks to go-unrecognised. It puts all essential styling inline, and keeps only the nice-to-have mouseover in the
` block - as that is the only place, it seems, where it could possibly be.