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

:target 為空時的 CSS 選擇器

CSS selector when :target empty(:target 為空時的 CSS 選擇器)
本文介紹了:target 為空時的 CSS 選擇器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要一個 css3 選擇器來定位一個元素,當 :target 等于元素的 id(簡單)或當 :target 為空(不可能?).很難解釋,我舉個簡單的例子.

I need a css3 selector to target an element when the :target equals the id of the element (easy) or when the :target is empty (impossible?). It’s hard to explain, so let me give you a simple example.

div {
  background: blue;
}
div:target, div:no-target {
  background: red;
}

當然 :no-target 偽類不存在 ;).不使用 Javascript 有沒有辦法解決這個問題?提前致謝!

But of course the :no-target pseudo class doesn’t exist ;). Is there a way around this without using Javascript? Thanks in advance!

推薦答案

嘆息.我覺得我正在復活一個死去的話題,但它需要一個真正的答案.

Sigh. I feel like I'm resurrecting a dead topic, but it needs a real answer.

僅使用 CSS 就可以做到這一點,只需使用 :last-child 和 一般兄弟組合子,形式為 :target ~ :last-child:

It's possible to do this with CSS alone, just by using :last-child and a general sibling combinator, in the form of :target ~ :last-child:

.pages > .page:target ~ .page:last-child,
.pages > .page {
    display: none;
}

/* :last-child works, but .page:last-child will not */
.pages > :last-child,
.pages > .page:target {
    display: block;
}

這些規則適用于以下步驟:

The rules applies in the following steps:

  1. 隱藏所有頁面
  2. 同時顯示目標頁面和最后一頁
  3. 如果一個頁面被定位,隱藏最后一頁(.page:target ~ .page:last-child)

(現場示例)

顯然,這與 舊版本中接受的答案非常相似,前面提到的相關帖子.

這篇關于:target 為空時的 CSS 選擇器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Does the CSS direct decendant (gt;) not have any value in selectivity?(CSS 直接后代 (gt;) 在選擇性方面沒有任何價值嗎?)
Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的結果是否有序?)
Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 錯誤:當使用 JS 刪除項目時,first-child 不更新 display:block)
nth-Child CSS selectors(nth-子 CSS 選擇器)
Using same ID for multiple HTML tags?(對多個 HTML 標簽使用相同的 ID?)
CSS: Select element only if a later sibling exists(CSS:僅當存在較晚的兄弟時才選擇元素)
主站蜘蛛池模板: 成人美女免费网站视频 | 99国内精品久久久久久久 | 日韩1区 | 麻豆久久 | 日韩精品成人一区二区三区视频 | 精品视频免费 | 午夜寂寞福利视频 | 韩国av电影网 | 欧美一级片中文字幕 | 欧美在线观看免费观看视频 | 亚洲一区二区不卡在线观看 | h在线 | 一呦二呦三呦国产精品 | av在线播放一区二区 | 亚洲国产精品成人久久久 | 一区在线免费视频 | 日韩中文字幕在线观看 | 成人免费视频 | 欧美一区二区大片 | 国产精品永久免费观看 | 久久精品视频免费观看 | 精品1区| 亚洲精品v日韩精品 | 国产精品国产三级国产a | 中文字幕成人免费视频 | 亚洲人成人一区二区在线观看 | 一区日韩 | 欧美日韩国产一区 | 成人在线观看中文字幕 | 欧美毛片免费观看 | 免费一区二区 | 99re6热在线精品视频播放 | 麻豆av电影网 | 久久婷婷麻豆国产91天堂 | 日韩手机在线看片 | 草草视频在线观看 | h片在线看| 欧美不卡一区二区三区 | 成人精品一区二区三区中文字幕 | 亚洲一区二区视频 | 免费观看一区二区三区毛片 |