只有在#user-favourites-card
內部確切存在10 div.favourite-image
時,我才選擇#user-favourites-card
中的第一個div.favourite-image
。選擇div內的第一個div,但僅當其中有10個時
我嘗試:
#user-favourites-card div.favourite-image:nth-last-child(10):first-child
的HTML來選擇:
<div _ngcontent-qcm-36="" class="card-noshadow" id="user-favourites-card">
<div _ngcontent-qcm-36="" class="first-card-header">
<h6 _ngcontent-qcm-36="">Favourites</h6>
</div>
<div _ngcontent-qcm-36="" class="row">
<!--template bindings={
"ng-reflect-ng-for-of": "[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
}--><div _ngcontent-qcm-36="" class="col-sm-6 col-md-4 col-xl-4">
<div _ngcontent-qcm-36="" class="favourite-image" ng-reflect-ng-style="[object Object]" style="background-image: url("result-images/dairy_free_parmesan_alternative_original.jpg");"></div>
</div><div _ngcontent-qcm-36="" class="col-sm-6 col-md-4 col-xl-4">
<div _ngcontent-qcm-36="" class="favourite-image" ng-reflect-ng-style="[object Object]" style="background-image: url("result-images/dairy_free_mozzarella_alternative.jpg");"></div>
</div><div _ngcontent-qcm-36="" class="col-sm-6 col-md-4 col-xl-4">
<div _ngcontent-qcm-36="" class="favourite-image" ng-reflect-ng-style="[object Object]" style="background-image: url("result-images/dairy_free_tasty_cheese_sauce.jpg");"></div>
</div><div _ngcontent-qcm-36="" class="col-sm-6 col-md-4 col-xl-4">
<div _ngcontent-qcm-36="" class="favourite-image" ng-reflect-ng-style="[object Object]" style="background-image: url("result-images/dairy_free_mild_cheese_mix.jpg");"></div>
</div><div _ngcontent-qcm-36="" class="col-sm-6 col-md-4 col-xl-4">
<div _ngcontent-qcm-36="" class="favourite-image" ng-reflect-ng-style="[object Object]" style="background-image: url("result-images/sugar_free_dark_chocolate_salted_caramel.png");"></div>
</div><div _ngcontent-qcm-36="" class="col-sm-6 col-md-4 col-xl-4">
<div _ngcontent-qcm-36="" class="favourite-image" ng-reflect-ng-style="[object Object]" style="background-image: url("result-images/alpro_drink_for_professional.jpg");"></div>
</div><div _ngcontent-qcm-36="" class="col-sm-6 col-md-4 col-xl-4">
<div _ngcontent-qcm-36="" class="favourite-image" ng-reflect-ng-style="[object Object]" style="background-image: url("result-images/alpro_custard.jpg");"></div>
</div><div _ngcontent-qcm-36="" class="col-sm-6 col-md-4 col-xl-4">
<div _ngcontent-qcm-36="" class="favourite-image" ng-reflect-ng-style="[object Object]" style="background-image: url("result-images/alpro_coconut_dessert.jpg");"></div>
</div><div _ngcontent-qcm-36="" class="col-sm-6 col-md-4 col-xl-4">
<div _ngcontent-qcm-36="" class="favourite-image" ng-reflect-ng-style="[object Object]" style="background-image: url("result-images/alpro_creamy_caramel.jpg");"></div>
</div><div _ngcontent-qcm-36="" class="col-sm-6 col-md-4 col-xl-4">
<div _ngcontent-qcm-36="" class="favourite-image" ng-reflect-ng-style="[object Object]" style="background-image: url("result-images/dairy_free_sour_cream_alternative.jpg");"></div>
</div>
</div>
</div>
題外話:我想選擇此確切元素,以證明有他們的10正好在茉莉花測試。
This page顯示瞭如何完成。我究竟做錯了什麼?
你可以清理一點點的HTML。有很多減價與問題無關,而且很難閱讀。 (例如圖片) – vals
@vals,但有人會說他們需要查看瀏覽器輸出的所有html。 – BeniaminoBaggins
@vals是正確的。大多數標記妨礙我們來幫助你。如果你讓你的代碼可執行,它也會很棒。 –