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

CSS and tables

Status
Not open for further replies.

bluedollar

Programmer
Jul 24, 2003
174
GB
I have created a website and have hard coded all the formatting into the HTML, what I want to do is use css to achieve what I am doing at the moment. However I am having problems with text that is displayed in tables, eg:

================================================
NON CSS

echo'<P>Dates: <br><br> <table border=&quot;1&quot;>';

echo'<tr><th bgcolor=&quot;#999999&quot;> Start Date:</th><td>'.$date_start[2].'/'.$date_start[1].'/'.$date_start[0].'</td></tr>';

echo'</table>';

===============================================
USING CSS

Does not display the same as:

echo'<style type=&quot;text/css&quot;>';
echo'<!--';
echo'H2 { background-color: #999999; }';
echo'-->';
echo'</style>';

echo'<P>Dates: <br><br> <table border=&quot;1&quot;>';

echo'<tr><th><h2>Start Date:</h2></th><td>'.$date_start[2].'/'.$date_start[1].'/'.$date_start[0].'</td></tr>';

echo'</table>';

============================================

The first example shows as:

--------------------------------------
:gggg header ggggg : :
--------------------------------------

g = gray = #999999

The second example shows as:

--------------------------------------
: gggg header ggggg : :
: : :
--------------------------------------

Question

- What can I do to rectify this.

Any help would be greatly apprecaited.

Thanks

Dan
 
there are a lot of attributes set to h2 tag, which you did not define. they're probably causing problem. replace H2 in style with TH, like so

<style type=&quot;text/css&quot;>
<!--
TH { background-color: #999999; }
-->
</style>

then get rid of h2 tag in the code:

echo'<tr><th>Start Date:</th><td>'.$date_start[2].'/'.$date_start[1].'/'.$date_start[0].'</td></tr>';

btw, you don't have to echo/print entire site with php. you can open/close php as many times as you like. just use it for code
 
Try this: You'll see there the presentation of the book &quot;HTML Utopia: Designing Without Tables Using CSS&quot; by Dan Shafer.
&quot;Now You Too Can Easily Create Modern ‘Table-free’ Websites Using CSS from scratch&quot;.
You can also download a few chapters in pdf format for free.
Hope to be of great help.
 
You're getting different results because you're doing different things. This is your HTML:
[tt]
<th bgcolor=&quot;#999999&quot;>Start Date:</th>
[/tt]
This, in effect is your CSS version:
[tt]
<th><h2 style=&quot;background-color:#999999&quot;>Start Date:</h2></th>
[/tt]
The CSS is being applied to a bit of text within the table cell, the bgcolor attribute was being applied to the whole cell.

What you need to do is apply your CSS to the cell instead, something like this:
[tt]
<style type=&quot;text/css&quot;>
.formlabel {background-color: #999999;}
</style>

...

<th class=&quot;formlabel&quot;>Start Date:</th>
[/tt]
Note that I'm using a named class rather than linking it to a particular tag, and that I've resisted the temptation to call the class &quot;greybg&quot;, naming it after what it's used for rather than what it looks like. That way, if you decide to change the colour scheme your class names still make sense.

Incidentally, you should really put your CSS declarations in a seperate stylesheet file, rather than putting them inline in the <head> of each page - it's much easier to maintain that way.



-- Chris Hunt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top