久久久久久久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?)
主站蜘蛛池模板: 日韩不卡一区二区三区 | 国产亚洲欧美在线视频 | www日本在线观看 | av网址在线播放 | 欧美日韩中文字幕在线 | 亚洲国产欧美一区二区三区久久 | 精品欧美一区免费观看α√ | 超碰97干| 无码一区二区三区视频 | 精久久久 | 国产精品久久久久久久久久久久冷 | 日韩国产精品一区二区三区 | 久久在线| 日韩在线免费视频 | 日韩色视频 | 成人免费看黄网站在线观看 | 亚洲一区二区中文字幕 | 国产精品视频专区 | 国产精品久久久久久久岛一牛影视 | 国产一区二区 | 日日操日日舔 | 在线免费观看黄色 | 日本在线你懂的 | 久久香焦| 青娱乐一区二区 | 福利视频网 | 免费成人在线网站 | 午夜资源| 国产一区二区小视频 | 精品日韩一区二区 | www精品美女久久久tv | 婷婷色婷婷 | 精品国产乱码久久久久久影片 | 狠狠操狠狠操 | 国产精品福利视频 | 欧美 日韩 亚洲91麻豆精品 | 中文字幕一区二区三区在线观看 | 亚洲国产一区在线 | 亚洲欧美一区二区三区视频 | 国产精品久久在线观看 | 日韩精品一区二区三区第95 |