Can’t get code to work in Table lesson


#1

Hi,

I’m having an issue with my code in one of the lessons on HTML tables: “Style That Head”.

The instructions are as follows:

"Make the "Famous Monster" and "Birth Year" labels emphasized (i.e. make them italicized).
Make the "Famous Monsters by Birth Year" title red.”

The code I entered does make the text italicized, and it does change the colour of the title to red. However, for some reason, the title is now right-adjusted instead of in the centre, where it’s supposed to be. Can someone please take a look, and tell me what I’m doing wrong? Thanks!

PS/ I added the code below, but it’s not showing up in the preview, so not even sure if you can see what I’ve added. :-/






#2
<tr>
                    <th colspan="2"><th style="color:red;">Famous Monsters by Birth Year</color></th>
                </tr>
                <tr style="border-bottom:1px solid black;">
                    <th style="padding:5px;"><em>Famous Monster</em></th>
                    <th style="padding:5px;border-left:1px solid black;"><em>Birth Year</em></th>
                </tr>

#3

What exactly is the error message?

The problem in your code is this line:

<th colspan="2"><th style="color:red;">Famous Monsters by Birth Year</color></th>

the problem is that now your first th tag isn't read, you can perfectly fine add two attributes to one html element, here is an example of image with two attributes:

<img src="#" alt="my image">

I suggest you make one <th> tag with both colspan and style


#4
Hi, thanks for the feedback!

The issue is that I didn’t know how to make one <th> tag with both colspan and style, as this hadn't been covered in any of the lessons up to that point. But after a bit of googling, I found the answer:

     <th colspan="2" style="color:red">Famous Monsters by Birth Year</th>>

#5

Yea, it indeed isn't mentioned before that you can multiply attributes to a html element, good you figured it out


#6

Thanks for this string. I had the same issue, which you two helped me solve.


#7

I am still getting an error that says I need to add a style attribute to the first <th> tag, which I did. What is wrong with this code?

<html>
    <head>
        <title>Table Time</title>
    </head>
    
    <body>
        
        <table style="border-collapse:collapse;">
            <thead>
                <tr>
                    <th colspan="2" style="color:red">Famous Monsters by Birth Year</th>
                </tr>
                <tr style="border-bottom:1px solid black;">
                    <th style="padding:5px;"><em>Famous Monster</em></th>
                    <th style="padding:5px;border-left:1px solid black;"><em>Birth Year</em></th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td style="padding:5px;">King Kong</td>
                    <td style="padding:5px;border-left:1px solid black;">1933</td>     
                </tr>
                
                <tr>
                    <td style="padding:5px;">Dracula</td>
                    <td style="padding:5px;border-left:1px solid black;">1897</td>
                </tr>
                
                <tr>
                    <td style="padding:5px;">Bride of Frankenstein</td>
                    <td style="padding:5px;border-left:1px solid black;">1944</td>
                </tr>
            </tbody>
        </table>
        
    </body>

</html>

#8

your code is fine, try a different browser