문제

I have a div container which may contain different kinds of child elements:

<div id="my-container">
    <p>...</p>
    <p>...</p>
    <div>...</div>
    <blockquote>...</blockquote>
    ...
</div>

I want to select the last element in my container and apply certain styles to it. But I don't know if the last element is a p, a div, or whatever. This is how I would do that:

#my-container > *:last-child {
    /* my styles */
}

Will this work in all mobile browsers?
(In this case, I don't care about desktop browsers.)

Thanks a lot!
Karl

도움이 되었습니까?

해결책

Prepending the universal selector is unnecessary in this case, since not specifying a selector before :last-child will still allow it to target any element that is a last-child within a parent.

The :last-child pseudo-class is also well supported among mobile browsers according to caniuse.

Instead just use:

#my-container > :last-child {
    /* my styles */
}

http://jsfiddle.net/utEUw/4/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top