久久久久久久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:僅當存在較晚的兄弟時才選擇元素)
主站蜘蛛池模板: 国产在线精品一区二区 | 亚洲精品一区国产精品 | 一本在线| 国产高清精品在线 | 欧美国产91 | 欧美成人一级视频 | 桃花av在线 | 91麻豆精品国产91久久久久久 | 中文字幕视频在线观看 | www日韩欧美| 国产精品免费一区二区三区四区 | 国产传媒在线观看 | 欧美精品a∨在线观看不卡 国产精品久久国产精品 | 欧美一区二区三区四区在线 | 免费观看一级毛片视频 | 亚洲综合色视频在线观看 | 精品国产一级 | 国产精品国产三级国产aⅴ中文 | 北条麻妃av一区二区三区 | 国产日韩中文字幕 | 在线天堂免费中文字幕视频 | 欧美一级二级三级 | 国产一级片一区二区 | 欧美精品在线视频 | 天堂网中文| 国产成人99久久亚洲综合精品 | 视频一区二区三区中文字幕 | 亚州精品天堂中文字幕 | www国产亚洲精品久久网站 | 日韩一区二区三区在线观看 | 欧美一区二区三区视频 | 日韩视频三区 | 中文字幕日韩专区 | 黄色成人av | 精久久久| 国产精品久久久免费 | 国产人久久人人人人爽 | 精品一区二区三区四区 | 午夜看片网站 | 欧美成人精品一区二区三区 | 亚洲在线 |