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

如何在css中顯示塊的前N個元素并隱藏其他元素

How to show the first N elements of a block and hide the others in css?(如何在css中顯示塊的前N個元素并隱藏其他元素?)
本文介紹了如何在css中顯示塊的前N個元素并隱藏其他元素?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我試圖隱藏塊 .container 內具有類 .row 的前 3 個元素.

I am trying to hide the first 3 elements having the class .row inside the block .container.

我正在做的是首先隱藏所有 .row,然后我嘗試使用 .row 顯示前 3 個 .row:nth-child(-n+3)

What I'm doing is hiding all the .row first, and then I am trying to display the first 3 .row by using .row:nth-child(-n+3)

jsfiddle 在這里:http://jsfiddle.net/z8fMr/1/

jsfiddle here: http://jsfiddle.net/z8fMr/1/

.row {
  display: none;
}

.row:nth-child(-n+3) {
  display: block;
}

<div class="content">

  <div class="notarow">I'm not a row and I must remain visible</div>
  <div class="row">Row 1</div>
  <div class="row">Row 2</div>
  <div class="row">Row 3</div>
  <div class="row">Row 4</div>
  <div class="row">Row 5</div>
  <div class="row">Row 6</div>

</div>

我這里有兩個問題:

  1. 第 3 行不顯示,是不是我用錯了 nth-child?
  2. 有沒有比隱藏所有內容然后創建特定規則來顯示我想要的前 n 個元素更好的做法?css 中有沒有辦法只顯示前 3 個 .row 然后隱藏所有其他 .row ?
  1. Row 3 is not displayed, am I using nth-child in the wrong way?
  2. Is there a better practice than hiding everything and then creating a specific rule to display the n first elements that I want? Is there a way in css to just display the first 3 .row and then hide all the other .row ?

謝謝.

推薦答案

  1. 您有一個 .notarow 作為第一個孩子,因此您必須在 :nth-child() 公式中考慮這一點.由于那個 .notarow,你的第一個 .row 成為了父級的第二個孩子,所以你必須從第二個到第四個開始計數:

  1. You have a .notarow as the first child, so you have to account for that in your :nth-child() formula. Because of that .notarow, your first .row becomes the second child overall of the parent, so you have to count starting from the second to the fourth:

 .row:nth-child(-n+4) {
     display: block;
 }

更新小提琴

.row {
    display: none;
}

.row:nth-child(-n+4) {
    display: block;
}

<div class="content">
    <div class="notarow">I'm not a row and I must remain visible</div>
    <div class="row">Row 1</div>
    <div class="row">Row 2</div>
    <div class="row">Row 3</div>
    <div class="row">Row 4</div>
    <div class="row">Row 5</div>
    <div class="row">Row 6</div>
</div>

你做的很好.

這篇關于如何在css中顯示塊的前N個元素并隱藏其他元素?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Style every third element?(每隔三個元素設置樣式?)
Why shouldn#39;t I use ID selectors in CSS?(為什么我不應該在 CSS 中使用 ID 選擇器?)
What does img[class*=quot;alignquot;] mean in CSS?(CSS 中的 img[class*=“align] 是什么意思?)
CSS: Last element on line(CSS:最后一個元素)
How do I select every other div class element using just CSS (no js)(如何僅使用 CSS(無 js)選擇所有其他 div 類元素)
Tool for checking unused CSS selectors?(檢查未使用的 CSS 選擇器的工具?)
主站蜘蛛池模板: 欧美在线一区二区三区 | 亚洲欧美综合精品久久成人 | 国产综合一区二区 | 中文字幕一页二页 | 91精品国产91久久久久久吃药 | 国产成人精品区一区二区不卡 | 亚洲欧美国产精品久久 | 国产精品不卡一区 | 欧美精品在线免费观看 | 亚洲精品乱码久久久久久蜜桃 | 天天干夜夜操 | 韩国精品一区 | 久久伊人亚洲 | 激情三区 | 国产成人精品久久 | 亚洲成人99 | 夜夜草天天草 | www久久国产 | 人人草天天草 | 午夜免费av | 国产一区二区三区四区 | 黑人巨大精品欧美一区二区免费 | 亚洲国产精品一区二区第一页 | 精品九九| 九一精品 | 精品国产精品国产偷麻豆 | 一区二区三区在线免费观看 | 黄色片网站国产 | 国产一区二区在线视频 | 中文字幕成人av | 国产精品视频免费观看 | 91免费在线视频 | 国产精品一级在线观看 | 国产精品视频一二三 | 一区二区在线免费观看视频 | 在线观看国产视频 | 亚洲成人av | 久久久久国产一区二区三区四区 | 91av免费看 | 亚洲 欧美 精品 | 亚洲精品中文字幕在线观看 |