Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

brandonlind2
brandonlind2
7,823 Points

why cant I make a th element display block?

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>new</title>
        <meta charset="utf-8">
        <meta name="description" content="this is a new test page, this is a new test page">
        <meta name="keywords" content="new,page,test">
        <style>
            body{
                background-color: blue;
                margin: auto;
                padding: 0,0,0,0;
            }
            table{
                margin: auto;
            }
            th{
                display: block; <!-- not working-->
            }
        </style>
    </head>
    <body>
        <table>
            <th>cell group 1</th>
            <td>cell 1</td>
            <td>cell 2</td>
            <td>cell 3</td>
            <th>cell group 2</th>
            <td>cell 2</td>
            <td>cell 3</td>
            <td>cell 4</td>
            <th>cell group 3</td>
            <td>cell 5</td>
            <td>cell 6</td>
            <td>cell 7</td>
        </table>
    </body>
</html>

2 Answers

Oana Giurgea
PLUS
Oana Giurgea
Courses Plus Student 14,283 Points

Every table must contains tbody and tr tags. A th tag has as inherit display: table-cell;

John Stuifbergen
John Stuifbergen
7,460 Points

I'm not sure what you're trying accomplish, but trying to style a th or td a display:block is really bending what these tags are semantically supposed to be doing. I noticed you're missing a <tr> tag. Does the example below meet your needs?

<table>
    <tr>
        <th colspan="3">cell group 1</th>
    </tr>
    <tr>
        <td>cell 1</td>
        <td>cell 2</td>
        <td>cell 3</td>
    </tr>
    <tr>
        <th colspan="3">cell group 2</th>
    </tr>
    <tr>
        <td>cell 2</td>
        <td>cell 3</td>
        <td>cell 4</td>
    </tr>
    <tr>
        <th colspan="3">cell group 3</td>
    </tr>
    <tr>
        <td>cell 5</td>
        <td>cell 6</td>
        <td>cell 7</td> 
    </tr>
</table>