Css: How to Select First Element in Each Row?

I have the following html fragment:

<div id = "fromAddress">
        <table>
            <tr><td id="from">From:</td>
                <td>
                    <table>
                        <tr><td>Acquirung Bank</td></tr>
                        <tr><td>Risk Management</td></tr>
                        <tr><td>100 Bond Street</td></tr>
                        <tr><td>London</td></tr>
                        <tr><td>W1</td></tr>
                    </table>
                </td>
            </tr>
            <tr><td>Fax:</td><td id="fromFax">0207 234567890/</td></tr>
            <tr><td>Tel:</td><td id="fromTel">0207 123456789/</td></tr>
        </table>
</div>

My css:

#fromAddress td:first-child
{
    font-weight: bold;
}

#fromAddress table table td:fist-child
{
    font-weight:normal;
}

How I can make text in first s bold? So, "From", "Fax", and "Tel" are bold?

2

1 Answer

Something like this:

#fromAddress > table > tbody > tr > td:first-child {
    font-weight: bold;
}

Chrome at least will add in the tbody tag, so you should probably add it to your html to ensure this works in all browsers.

Or to avoid all the '>'s you could do:

td:first-child {
    font-weight: bold;
}

table table td:first-child {
    font-weight: normal;
}
4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest