亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

:nth-of-type無效

:nth-of-type無效

慕先生4543078 2017-06-26 16:34:25
<div?class="outside"> ????<div?class="box"> ????????<div?class="inside"></div> ????????<div?class="line"></div> ????</div> ????<div?class="anotherLine"></div> ????<div?class="box"> ????????<div?class="inside"></div> ????????<div?class="line"></div> ????</div> ????<div?class="anotherLine"></div> ????<div?class="box"> ????????<div?class="inside"></div> ????????<div?class="line"></div> ????</div> ????<div?class="anotherLine"></div> ????<div?class="box"> ????????<div?class="inside"></div> ????????<div?class="line"></div> ????</div> ????<div?class="anotherLine"></div> </div>.outside{ ????width:?100%; ????padding-bottom:?20px; ????padding-top:?20px; ????background:?grey; } .inside{ ????width:?100px; ????height:?100px; ????background:?red; } .box{ ????margin-left:?50px; ????position:?relative; ????display:?inline-block; } .line{ ????width:?80px; ????height:?2px; ????background:?white; ????margin-top:?5px; } .anotherLine{ ????width:?2px; ????height:?100px; ????background:?blue; ????display:?inline-block; } .outside?.box:nth-of-type(2)?.inside{ ????background:?black; }結果我想把第二個紅色的塊變成黑色的,結果失敗了。但是如果把上面的HTML修改一下<div?class="outside"> ????<div?class="box"> ????????<div?class="inside"></div> ????????<div?class="line"></div> ????</div> ????<!--?<div?class="anotherLine"></div>?--> ????<div?class="box"> ????????<div?class="inside"></div> ????????<div?class="line"></div> ????</div> ????<!--?<div?class="anotherLine"></div>?--> ????<div?class="box"> ????????<div?class="inside"></div> ????????<div?class="line"></div> ????</div> ????<!--?<div?class="anotherLine"></div>?--> ????<div?class="box"> ????????<div?class="inside"></div> ????????<div?class="line"></div> ????</div> ????<!--?<div?class="anotherLine"></div>?--> </div>這樣就成功了。請問這是為什么?:nth-of-type能使用的場合只能是被選中元素的父類中的元素全部相同嗎?如果不按照第二種方式,保留藍色的豎線,我要怎么修改樣式表?
查看完整描述

1 回答

已采納
?
李曉健

TA貢獻1036條經驗 獲得超461個贊

雖然我不知道什么原因,但是把<div class="anotherLine"></div> 換成p標簽就好了 <p class="anotherLine"></p>。

其實那個<p class="anotherLine"></p> 也可以不用要,用偽類也可以實現。


如果你的問題已解決,請記得采納答案!

查看完整回答
反對 回復 2017-06-26
  • 1 回答
  • 0 關注
  • 2384 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號