1

I am working with the following code:

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <style type="text/css">
    td.one
    {
      align="center";
      colspan="3";
      bgcolor="lightgrey";
      style="font-size:15px;font-weight:bold;"
    }
  </style>
</head>

<body>
  <table border="1" cellspacing="1" cellpadding="1" width="100%">
   <tr>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td class="one">Session 1</td>
     <td class="one">Session 1</td>
   </tr>
</body>

This CSS is not working for me. I want to make classes so different <td> elements will have different appearances.

1
  • 3
    HTML and CSS are not programming languages =) Commented May 7, 2009 at 19:39

3 Answers 3

11

You're using HTML attribute names and syntax in your stylesheet, whereas you need to be using CSS names and syntax:

<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style type="text/css">
            td.one
            {
                text-align: center;
                /* There's no way to do colspan="3" in CSS */
                background-color: lightgrey;
                font-size: 15px;
                font-weight:bold;
            }
        </style>
    </head>

<body>
  <table border="1" cellspacing="1" cellpadding="1" width="100%">
   <tr>
     <td> </td>
     <td> </td>
     <td class="one">Session 1</td>
     <td class="one">Session 1</td>
   </tr>
</body>
Sign up to request clarification or add additional context in comments.

1 Comment

The colspan can of course be set in the HTML: <td class="one" colspan="3">
2

There's two things wrong with your current code. First, you're trying to set attributes of td with CSS, which isn't possible - you can only change styles. You have to set the align, colspan and bgcolor attributes inline (though there are CSS equivalents of some of these).

Second, the syntax is incorrect for your CSS rules. It should look like this:

td.one
{
    font-size: 15px;
    font-weight: bold;
}

Comments

-2
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style type="text/css">
        td.one
        {
            text-align:"Center";
            background-color:Gray;
            font-size:15px;
            font-weight:bold;
        }
    </style>
</head>

<body>
  <table border="1" cellspacing="1" cellpadding="1" width="100%">
   <tr>
     <td> </td>
     <td> </td>
     <td class="one" colspan="3">Session 1</td>
     <td class="one">Session 1</td>
   </tr>
</body>

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.