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

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

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

問題描述

我試圖隱藏塊 .container 內(nèi)具有類 .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èi)容然后創(chuàng)建特定規(guī)則來顯示我想要的前 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 成為了父級的第二個孩子,所以你必須從第二個到第四個開始計數(shù):

  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>

你做的很好.

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

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

相關(guān)文檔推薦

Style every third element?(每隔三個元素設(shè)置樣式?)
Why shouldn#39;t I use ID selectors in CSS?(為什么我不應(yīng)該在 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 選擇器的工具?)
主站蜘蛛池模板: 日韩成人影院 | 国产欧美精品一区二区三区 | 日韩免费在线视频 | 免费看的毛片 | 伊人精品综合 | 亚洲一区在线看 | 国产精品综合 | 欧美一区二区在线 | 欧美日韩亚洲一区二区 | 一区二区三区四区在线 | 成人激情视频网 | 一区二区三区四区精品 | 在线免费观看黄色片 | 日韩中文字幕在线观看 | 一区二区不卡 | 欧美久久久久久久久 | 亚洲第一天堂网 | 日韩色黄大片 | 福利视频二区 | 国产精品伦理一区 | 国产成人在线免费视频 | 亚洲综人网 | 日韩免费高清视频 | 久久高清免费视频 | 黄大色黄大片女爽一次 | 成年人的免费视频 | 亚洲h网站 | 黑人精品一区二区 | 福利小视频 | 91看片在线观看 | 欧美激情一区二区 | 精品一区二区三区免费看 | 成人动漫在线观看 | 国产精品手机在线 | 老司机精品福利视频 | 成人羞羞网站 | 日韩成人影院 | 亚洲福利视频一区 | 人人干人人爱 | 成人免费视频网站在线观看 | 国产一区二区三区四区 |