A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

How to highlight the background of alternate table row using CSS
Q:

How to highlight the background of alternate table row using CSS

0

How to highlight the background of alternate table row using CSS

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the CSS ":nth-child" selector

You can use the CSS3 :nth-child selector to highlight the background of alternate table row for creating a zebra-striped table. The :nth-child(N) pseudo-class accepts an argument N, which can be a keyword, a number, or a number expression of the form xn+y where x and y are integers (e.g. 1n2n3n2n+13n-2, …). Try out the following example to see how it works:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Highlighting Alternate Table Row Using CSS</title>
<style>
    table{
        margin: 30px;
        border-collapse: collapse;
    }
    table tr{
        border-bottom: 1px solid #666;
    }
    table tr:nth-child(2n){
        background: #f2f2f2;
    }
    table th, table td{
        padding: 10px;
    }
</style>
</head>
<body>
    <table>
        <tr>
            <th>Row</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Email</th>
        </tr>
        <tr>
            <td>1</td>
            <td>John</td>
            <td>Carter</td>
            <td>johncarter@mail.com</td>
        </tr>
        <tr>
            <td>2</td>
            <td>Peter</td>
            <td>Parker</td>
            <td>peterparker@mail.com</td>
        </tr>
        <tr>
            <td>3</td>
            <td>John</td>
            <td>Rambo</td>
            <td>johnrambo@mail.com</td>
        </tr>
        <tr>
            <td>4</td>
            <td>Harry</td>
            <td>Potter</td>
            <td>harrypotter@mail.com</td>
        </tr>
    </table>
</body>
</html>

output:

Row First Name Last Name Email
1 John Carter johncarter@mail.com
2 Peter Parker peterparker@mail.com
3 John Rambo johnrambo@mail.com
4 Harry Potter harrypotter@mail.com

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now