0

I am no beginner with HTML and CSS... but I am with PHP. I have a very tiny dynamically generated PHP page that creates a table and fills it with numbers. The CSS is working on random items, very weirdly and I'm not sure what is going on. The <body> tag CSS is not working at all. Not one property is being affected by it. The table.temps css is not working either, but if I remove it, then the <th> tag looses its styling. This is for a homework assignment and I know it's an easy fix, I've just been having the worst time with CSS and PHP lately.

It's all one page, and its relatively small, so here is the document:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<title>Lab 1</title> 

<style type="text/css">
<!-- Declare document <body> styles -->
body{
    background-color: #9FDBFF;
    color: #333;
    font-family: Helvetica, sans-serif;
    font-size: .8em;
    height: 100%;
    width: 100%;
}

<!-- Declare document table styles -->
table.temps {
    width: 50%;
    height: auto;
    min-height: 400px;
    border: 2px solid black;
    color: #333;
}

th {
    background: blue;
    color: #FFF;
    height: 20px;
    width: 100px;
}

.colorIt {
    background-color: #CCC;
}
</style>

</head>
<body>
<?php

$intTableTotalWidth = 8;
$intTableTotalHeight = 8;
$intCount = 1;

print("<table class='temps'>");
print("<th>Farenheight</th>");
print("<th>Celcius</th>");

for ($intHeight = 0; $intHeight < $intTableTotalHeight; $intHeight++) {
print("<tr>");

for ($intWidth = 0; $intWidth < $intTableTotalWidth; $intWidth++) {

    if ($intCount % 2 == 0){
        print("<td class='colorIt'>" . $intCount ."</td>");
    }
    else {
        print ("<td>" . $intCount . "</td>");
    }

    $intCount++;
}

print("</tr>");
}

print("</table>");
?>
</body>
</html>

EDIT: My fault people, I didn't even realize I was using HTML comments in the CSS. It's internal CSS so the CSS comments don't change color in the HTML document which was throwing me off. I fixed the issue. I appreciate your input!

2
  • 1
    Use CSS comments in the style block, don't use html comments. /* */ vs <!-- --> Commented Sep 27, 2012 at 16:32
  • 1
    Also, your <th> elements should be wrapped in a <tr> Commented Sep 27, 2012 at 16:34

4 Answers 4

3

You are using html comments in the style tag. This is not allowed. You should never use html comments in style and script tags.It's not allowed. Remove them and it will all work.

Sign up to request clarification or add additional context in comments.

Comments

2

remove these lines

<!-- Declare document <body> styles -->
<!-- Declare document table styles -->

Comments

0
  1. Your <th> tags should be embeded in <tr> tags: <tr><th>col1</th><th>col2</th></tr>.

  2. You are outputing more cells / row than columns defined with <th>. If you want a <th> to contain two columns, you should use <th colspan="2">col1</th>.

Comments

0

much easier sollution: have session_start() at begining of .php file, put all your theme in a array and later, include stylesheet

session_start()
$theme=array("links"=>"#ff0000", "bkg"=>"#00ff00");
$_SESSION["Theme"]=$theme;
...
<link rel="stylesheet" type="text/css" href="default.php">

and your stylesheet look like this: default.php

<?php session_start();
if (isset($_SESSION["Theme"])) {
    extract($_SESSION["Theme"]);
    header("Content-type: text/css");
} else {
// this part is for proper coloring the file, editor will see <style> 
// but when loaded from main file <style> will be discarded     
?>
<style>
<?php } ?>
a {
   color:<?=$links?>;      
}

body {
    background-color: <?=$bkg?>;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.