css子选择器选择最后一个div

the*_*bui 2 css

<body>
    <div>content 1</div>
    <div>content 2</div>
    <div>content 3</div>
</body>
Run Code Online (Sandbox Code Playgroud)

如何在不使用任何id或类的情况下选择最后一个标签.我已经尝试过了:

body:last-child {
        clear: both;
        background-color:red;
}
Run Code Online (Sandbox Code Playgroud)

请帮忙

谢谢

但这是css3所以浏览器(ipad safari)不会识别它.

Mus*_*usa 6

body:last-child 选择一个身体标签,它是其父母的最后一个孩子,试试

body > :last-child
Run Code Online (Sandbox Code Playgroud)


Rob*_*b W 5

使用子选择器(>):

body > :last-child {
    clear: both;
    background-color:red;
}
Run Code Online (Sandbox Code Playgroud)