課程
/前端開(kāi)發(fā)
/HTML/CSS
/十天精通CSS3
不明白的 .post p:last-child和.post :last-child有什么區(qū)別,效果不都是一樣的嗎
2018-09-04
源自:十天精通CSS3 6-7
正在回答
:last-child (選擇父元素的最后一個(gè)子元素)
??<style>???.post:last-child{/*有效,標(biāo)簽里所有元素*/????color:pink;???}???.post div:last-child{/*如果最后一個(gè)標(biāo)簽是<div>的時(shí)候,它就有效*/
?????color:blue;???}???.post p:last-child{/*如果最后一個(gè)標(biāo)簽是<p>的時(shí)候,它就有效*/
?????color: red;???}???.post a:last-child{??? ?color: orange;/*如果最后一個(gè)標(biāo)簽是<a>的時(shí)候,它就有效*/???}</style>?</head>?<body>???<div class="post">???? <p>我是p-1</p>???? <p>我是p-2</p>???? <p>我是p-3</p>???? <div>我是div-1</div>???? <p>我是p-4</p>???? <p>我是p-5</p>???? <div>我是div-2</div><!--現(xiàn)在這里就是最后一個(gè)標(biāo)簽 是div標(biāo)簽,字體會(huì)變成藍(lán)色-->???? <!--<a>我是插班生</a>-->???</div>???</body>
慕萊塢9334362 提問(wèn)者
舉報(bào)
本課程為CSS3入門(mén)教程,深刻詳解CSS3知識(shí)讓網(wǎng)頁(yè)穿上絢麗裝備
4 回答nth-child()和nth-of-type()的區(qū)別
3 回答有 nth-last-child(n),為何沒(méi)有nth-first-child(n) ?
2 回答ol > li:first-child{ color: red; }與 li:first-child{ color: red; }有區(qū)別嗎?
5 回答最后last-child 怎么刪不去
6 回答.wrapper>p:first-of-type和.wrapper>p:first-child 有什么區(qū)別嗎
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢(xún)優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-09-05
:last-child (選擇父元素的最后一個(gè)子元素)
??<style>
???.post:last-child{/*有效,標(biāo)簽里所有元素*/
????color:pink;
???}
???.post div:last-child{/*如果最后一個(gè)標(biāo)簽是<div>的時(shí)候,它就有效*/
?????color:blue;
???}
???.post p:last-child{/*如果最后一個(gè)標(biāo)簽是<p>的時(shí)候,它就有效*/
?????color: red;
???}
???.post a:last-child{
??? ?color: orange;/*如果最后一個(gè)標(biāo)簽是<a>的時(shí)候,它就有效*/
???}
</style>
?</head>
?<body>
???<div class="post">
???? <p>我是p-1</p>
???? <p>我是p-2</p>
???? <p>我是p-3</p>
???? <div>我是div-1</div>
???? <p>我是p-4</p>
???? <p>我是p-5</p>
???? <div>我是div-2</div><!--現(xiàn)在這里就是最后一個(gè)標(biāo)簽 是div標(biāo)簽,字體會(huì)變成藍(lán)色-->
???? <!--<a>我是插班生</a>-->
???</div>
??
?</body>