Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tr:last-child not working

Tags:

css

Probably some stupid reason for it not working, but i tend to mess up the css a bit. So maybe it will apply to others aswell. CSS:

.bet_history table {
    width: 1000px;
    display: block;
    border-collapse: collapse;
}
.bet_history td {
    padding: 0;
    font-size: 13px;
    text-align: center;
    padding-top: 1px;
    padding-bottom: 1px;
    background: #0361ba;
    color: #BDD6CE;
}
.bet_history tr {
    border-bottom: 1px solid black;
}
.bet_history tr:last-child {
    background: red;
}
.bet_history td.bet_history2 {
    color: #F0F0F0;
    width: 650px;
}
.bet_history td.bet_history1 {
    background-color: #0354a1;
    color: white;
    width: 100px;
    cursor: pointer;
    -o-transition:.5s;
    -ms-transition:.5s;
    -moz-transition:.5s;
    -webkit-transition:.5s;
    transition:.5s;
}
.bet_history td.bet_history1:hover {
    color: #3399FF;
}

And here is the HTML: Edited!

<div id="main">

admin1<br />


<table class="bet_history">

<tr><td style="width: 250px;">Bet ID: #6. 09-22-2014 16:08</td><td class="bet_history1">Match ID #6</td><td class="bet_history2"><span style="color: #00FFFF;">10000</span> minerals on Cure(2.00). Your bet returned <span style="color: #00FFFF;">0</span> minerals. Better luck next time!</td></tr><tr><td style="width: 250px;">Bet ID: #5. 09-22-2014 16:06</td><td class="bet_history1">Match ID #4</td><td class="bet_history2"><span style="color: #00FFFF;">2222</span> minerals on Snute(2.30). Your bet returned <span style="color: #00FFFF;">5110.6</span> minerals. Congratulations!</td></tr><tr><td style="width: 250px;">Bet ID: #4. 09-22-2014 15:58</td><td class="bet_history1">Match ID #4</td><td class="bet_history2"><span style="color: #00FFFF;">2222</span> minerals on Snute(2.30). Your bet returned <span style="color: #00FFFF;">5110.6</span> minerals. Congratulations!</td></tr><tr><td style="width: 250px;">Bet ID: #3. 09-22-2014 15:25</td><td class="bet_history1">Match ID #5</td><td class="bet_history2"><span style="color: #00FFFF;">600</span> minerals on Lars(4.00). Your bet returned <span style="color: #00FFFF;">2400</span> minerals. Congratulations!</td></tr><tr><td style="width: 250px;">Bet ID: #2. 09-22-2014 12:03</td><td class="bet_history1">Match ID #3</td><td class="bet_history2"><span style="color: #00FFFF;">64</span> minerals on naniwa(9.00). Your bet returned <span style="color: #00FFFF;">576</span> minerals. Congratulations!</td></tr><tr><td style="width: 250px;">Bet ID: #1. 09-20-2014 16:00</td><td class="bet_history1">Match ID #1</td><td class="bet_history2"><span style="color: #00FFFF;">20</span> minerals on Snute(2.20). Your bet returned <span style="color: #00FFFF;">44</span> minerals. Congratulations!</td></tr>
</table>
</div>

Why is the last-child not applying to the last tr? It will if i set it to td. Im sure its some stupid thing i did in the css.. This is no finished product. Im just wondering why the last-child doesnt work.

like image 983
Anders Holm Avatar asked Sep 23 '14 11:09

Anders Holm


People also ask

Why is my last child not working?

:last-child will not work if the element is not the VERY LAST element. I think it's crucial to add/emphasize that :last-child will not work if the element is not the VERY LAST element in a container.

How do you use the last child in SCSS?

The Last Child selector is a selector that allows the user to target the last element inside the containing element. This selector is also known as a Structural Pseudo class which means it is used for styling content on the basis of parent and child content.

Which nth child () selector will target only the last list item?

The :nth-last-child(n) selector matches every element that is the nth child, regardless of type, of its parent, counting from the last child. n can be a number, a keyword, or a formula.


1 Answers

As @Vucko mentioned in the comments the tr:last-child style is applied, however the td's in that row override that style.

If you want all the td's in the last row to be red edit your class to:

.bet_history tr:last-child td {
    background: red;
}

FIDDLE

like image 81
Danield Avatar answered Oct 12 '22 16:10

Danield