css lookup table the first few lines of the columns

css lookup table first few lines of columns

Definitions: ntn-child (n) is selected for implementation. Where n represents selected elements of several elements, the first of several to write a few special, to select the first can be written as:

first-child, should be written as a final check, last-child, to choose an even number, can be written as nth-child (2n), Similarly, the odd column can be written as nth-child (2n + 1), which not only suitable for table columns, but also for all selected elements.

Core codes: Table TR: Nth-Child (n) TD: Nth-Child (n) , a first n n-th row is selected, the second select n n-th column.

(Related courses recommended: CSS video tutorial )

Code Example:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        td{
            padding: 8px;
        }
        / * Here selected row 2, column 1, it set the background to red * /
        table tr:nth-child(2) td:nth-child(1){
            background-color: red;
        }
    </style>
</head>
<body>
    <table>
        <tr>
            <td>1,1</td>
            <td>1,2</td>
        </tr>
        <tr>
            <td>2,1</td>
            <td>2,2</td>
        </tr>
        <tr>
            <td>3,1</td>
            <td>3,2</td>
        </tr>
        <tr>
            <td>4,1</td>
            <td>4,2</td>
        </tr>
    </table>
</body>
</html>

Guess you like

Origin www.cnblogs.com/gechen/p/12047259.html