How I create a table that way just like that anyway

Asked

Viewed 39 times

-1

1 answer

2


Using colspan, if you intend that a column (<td>) specifies occupy the space equivalent to 3 columns then seven in the desired column <td colspan="3">, if it were to occupy the space of 4 columns would be <td colspan="4">

Example:

.tabela, .tabela td {
    border: 1px solid #000;
}

.tabela {
    border-collapse: collapse;
    width: 100%;
}
<table class="tabela">
    <tbody>
        <tr>
            <td colspan="3">Atendimento</td>
            <td colspan="3">Público</td>
        </tr>
        <tr>
            <td>Pres</td>
            <td>Tel</td>
            <td>Email</td>

            <td>Est</td>
            <td>Prof</td>
            <td>Out</td>
        </tr>
        <tr>
            <td>foo</td>
            <td>bar</td>
            <td>baz</td>

            <td>SP</td>
            <td>Foo Bar</td>
            <td>Baz Bar</td>
        </tr>
    </tbody>
</table>


Note that I only used <tr> and <td>, but you can separate what is the "header" from the table and use TH, which would be more because of semantics (could also use combined with the attribute scope="", which might be interesting to combine a CSS to customize, but this is another story):

.tabela, .tabela td, .tabela th {
    border: 1px solid #000;
}

.tabela {
    border-collapse: collapse;
    width: 100%;
}
<table class="tabela">
    <thead>
        <tr>
            <th colspan="3">Atendimento</th>
            <th colspan="3">Público</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th>Pres</th>
            <th>Tel</th>
            <th>Email</th>

            <th>Est</th>
            <th>Prof</th>
            <th>Out</th>
        </tr>
        <tr>
            <td>foo</td>
            <td>bar</td>
            <td>baz</td>

            <td>SP</td>
            <td>Foo Bar</td>
            <td>Baz Bar</td>
        </tr>
    </tbody>
</table>

  • my thanks was that same...... to having late all time that did not use table vlw same

  • @kauajotta thank you. PS: if you want a column to occupy two lines or more (which would be the reverse of the answer) the attribute is rowspan ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.