Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printable colours in div background 1

Status
Not open for further replies.

DaveC426913

Programmer
Jul 28, 2003
274
CA
The short question:

How can I allow a user to print a page so that it that prints the background-color of certain <divs/tables/1x1.gif/any object that can serve as a spacer>?



The long question:

I'm making a website that uses PHP to place little swatches of colour in a box. The colour hexcodes are pulled from a database.

The following code will create a tiny box with 1-to-n vertical swatches in it. I've included the table code and PHP code just for context.

All I really care about is either getting background-color: #nnnnnn to print out, or re-doing the divs so that the colour *will* print (i.e. I don't *have* to use divs if there's a better way - Any object that can be used as a spacer will do, as long as I can set its *colour* programmatically).




<table cellspacing="0" cellpadding="0" style="border: silver solid 1px;">
<tr>
<?
#loop through each colour, place a swatch of the colour
for ($j=1; $j<=$numColoursInPalette;$j++){
$sql = "SELECT Code FROM Colours WHERE `ID`='".$StylePaletteRow["Clr".$j]."'";
$resultG = mysql_query($sql);
$ColourRow=mysql_fetch_array($resultG)
?>
<td><div class="spcr" style="height: <?=$swatchsize?>px; width:<?=($swatchsize/$numColoursInPalette)?>px;
background-color: <?=$ColourRow['Code']
?>;" /></td>
<? } ?>
</tr>
</table>
 
I'll start by saying that this probably isn't the best solution by any means. That said, there is an option that the users can flag to print out background colors of items. If asking the user to turn on this option is not a valid solution, then instead you can use buttons as your spacer items. Style them to remove the borders and set appropriate width and height. When printing, the background colors for buttons are printed by default.

-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
You are a god among mere mortals. That button solution is primo.
 
Thanks for the kind words. I don't know that it's a primo solution..... but it's something to work off I suppose.

-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top