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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Background image

Status
Not open for further replies.

CliffLandin

Programmer
Nov 14, 2004
81
US
I am new to xhtml and don't know a whole lot about defining rules or anything like that, with that preface this is the problem I am having.
I have a page that changes the background of a table base on the page that you are on. This is done with a simple PHP if statement. As far as I can tell I can't validate the page since background is not a table attribute. How can I define the background of this table to be an image based on a variable passed in the url?
 
Background is not a thing you can set through HTML altogether. You would have to use CSS, which works with HTML to control the display of the page. You can set CSS inline (not recommended) in the head or in a separate css sheet. Here is the second option:
Code:
<style type="text/css">
.myTable {
  background: url(myimage.jpg);
}
</style>

<table class="myTable">
 <tr>
  <td></td>
 </tr>
</table>
 
I think that that will work just fine. Thanks!

When in doubt, go flat out!
 
Vragabond, regarding this statement:
"You can set CSS inline (not recommended)"

I am still very much on the lower rungs of the CSS ladder, and am wondering if you could expand on why inline style is to be avoided. Is it to do with rendering time?
Thanks for your help.


Regards, Andy.
**************************************
My pathetic attempts at learning HTML can be laughed at here:
 
CSS should separate design from content and by using an inline style you're breaking that rule. Code is a lot more cluttered if it has inline styles as opposed to separate stylesheet and inline styles are not reusable, meaning that you have to copy all the code to another element when you want to use it as opposed to only having the class or id. There is nothing wrong with using a single css declaration inline, if it is just a small thing that will not appear anywhere else. If not, it is better to put it in a separate sheet and have it available to be reused at any time.
 
Thanks for that input, Vragabond.
As it happens, that's how I suspected things should be - inline styles for one-off occurrences, although I see external style sheets occasionally which have all style rules listed, even if they are to be used only once. I'm assuming this practice simply bloats out the CSS file unnecessarily, and there should be a sensible mix of inline, embedded and external rules.

Regards, Andy.
**************************************
My pathetic attempts at learning HTML can be laughed at here:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top