1

I simply want to style every other row in a table I've generated using map tips with a different coloured background. I've got the correct generic CSS (I think) but nothing is changing.

tr:nth-child (odd) {
background:grey!important;
}

Below is the CSS styling for the table, I feel the contents of the table is irrelevant to show as code but I have shown an image below.

<style> 

body { 
background-color: white!important; 
font-family: sans-serif;
width: 200px;
} 

table { 
border-collapse: collapse; 
} 

th { 
font-size: 20px;
text-transform: uppercase;
padding: 10px;
background: grey;
color: white;
}

tr { 
border: 2px solid white; 
} 

tr:nth-child (odd) {
background:grey!important;
}

td { 
font-size: 12px;
white-space: nowrap; 
padding: 5px; 
}

td.h2{
font-size: 15px; 
float: left!important;
font-weight: bold;
background:grey;
}

td.bold { 
font-size: 12px; 
font-weight: bold; 
} 

td.gap { 
background-color:white; 
padding:1px; 
} 

</style> 

enter image description here

2

Using your style,only need add:

.table tr:nth-child(odd){ background: #b8d1f3; }

.table tr:nth-child(even){ background: #dae5f4; }

And put your table class when create the table,for example:

    <style> 

        body { 
        background-color: white!important; 
        font-family: sans-serif;
        width: 200px;
        } 

        table { 
        border-collapse: collapse; 
        } 

        th { 
        font-size: 20px;
        text-transform: uppercase;
        padding: 10px;
        background: grey;
        color: white;
        }

        tr { 
        border: 2px solid white; 
        } 

        tr:nth-child (odd) {
        background:grey!important;
        }

        td { 
        font-size: 12px;
        white-space: nowrap; 
        padding: 5px; 
        }

        td.h2{
        font-size: 15px; 
        float: left!important;
        font-weight: bold;
        background:grey;
        }

        td.bold { 
        font-size: 12px; 
        font-weight: bold; 
        } 

        td.gap { 
        background-color:white; 
        padding:1px; 
        } 
        .table tr:nth-child(odd){ 
        background: #b8d1f3;
        }

        .table tr:nth-child(even){
        background: #dae5f4;
        }

    </style>

    <table class="table">
        <th><h1>Alternating Table Rows</h1></th>

    <tr><td class="bold">Name:</td><td>[% "NAME" %] </td></tr>
    <tr><td class="bold">Use:</td><td> [% "USE" %] </td></tr>
    <tr><td class="bold">Elevation:</td><td>[% "ELEV" %]</td></tr>
</table>

And the result is:

enter image description here

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.