久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

用 :nth-child 選擇一半的元素?

Selecting half the elements with :nth-child?(用 :nth-child 選擇一半的元素?)
本文介紹了用 :nth-child 選擇一半的元素?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

以下面的代碼為例:

<ul>
  <li>Hello World</li>
  <li>Hello World</li>
  <li>Hello World</li>
  <li>Hello World</li>
</ul>

是否有可能,使用 :nth-child() 或其他方式,準(zhǔn)確選擇總元素的 一半?代碼應(yīng)該在上面的實(shí)例中選擇第一個(gè)/最后一個(gè) 兩個(gè) lis,然后如果我將 lis 的數(shù)量增加到六個(gè),它將選擇第一個(gè)/最后一個(gè)三個(gè).

Is it possible, using :nth-child() or otherwise, to select exactly half of the total elements? The code should select the first/last two lis in the above instance, then if I were to increase the number of lis to six, it would select the first/last three.

我覺(jué)得我將不得不使用 JavaScript...

I feel I'm going to have to use JavaScript...

推薦答案

在純 CSS 中接近的唯一方法是在任一 nth-child(odd)nth-child(even).如果你想要準(zhǔn)確的后半部分(而不是奇數(shù)或偶數(shù)),那么你必須使用 JavaScript/jQuery.

The only way you'd be able to get anywhere near to that in pure CSS is to do a selector on either nth-child(odd) or nth-child(even). If you want exactly the last half (and not either odd or even), then you'd have to use JavaScript/jQuery.

使用 jQuery,您可以使用:

Using jQuery, you could get them using:

var yourList = $("ul li");

yourList = yourList.slice(0, Math.floor(yourList.length/2));

這篇關(guān)于用 :nth-child 選擇一半的元素?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

CSS selector when :target empty(:target 為空時(shí)的 CSS 選擇器)
Does the CSS direct decendant (gt;) not have any value in selectivity?(CSS 直接后代 (gt;) 在選擇性方面沒(méi)有任何價(jià)值嗎?)
Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的結(jié)果是否有序?)
Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 錯(cuò)誤:當(dāng)使用 JS 刪除項(xiàng)目時(shí),first-child 不更新 display:block)
nth-Child CSS selectors(nth-子 CSS 選擇器)
Using same ID for multiple HTML tags?(對(duì)多個(gè) HTML 標(biāo)簽使用相同的 ID?)
主站蜘蛛池模板: 亚洲黄色在线免费观看 | 精品视频一区二区三区在线观看 | 91av小视频| 国产精品成人国产乱一区 | 超碰在线免费公开 | 国产91九色 | 91精品久久久久久久久久小网站 | 亚洲人成网亚洲欧洲无码 | 日本精品一区二区三区视频 | 一区精品视频在线观看 | 亚洲综合视频一区 | 日韩在线欧美 | 国产va| 国产日韩欧美一区二区 | 亚洲视频欧美视频 | 黄色国产视频 | 欧美日韩在线一区二区 | 欧美激情视频一区二区三区免费 | 超碰在线国产 | 色视频一区二区 | 999国产精品视频 | 精品无码久久久久久久动漫 | 欧美一级黄色片 | 天天久久| 久久国产成人精品国产成人亚洲 | 国产午夜精品理论片a大结局 | 日韩在线观看网站 | 久久久久久久一区 | 黄色毛片黄色毛片 | 一级美国黄色片 | av黄色片在线观看 | 亚洲国产一区二区视频 | 97在线观看 | 成人在线中文字幕 | 亚洲一区日韩 | 亚洲超碰在线观看 | 国产精品.xx视频.xxtv | 欧美性猛交一区二区三区精品 | 中文字幕在线视频免费观看 | 国产一区二区在线免费 | 国产精品夜夜夜一区二区三区尤 |