What does the “~” (tilde/squiggle/twiddle) CSS selector mean?

后端 未结 5 1297
孤街浪徒
孤街浪徒 2020-11-21 05:13

Searching for the ~ character isn\'t easy. I was looking over some CSS and found this

.check:checked ~ .content {
}

What does

5条回答
  •  失恋的感觉
    2020-11-21 06:02

    Good to also check the other combinators in the family and to get back to what is this specific one.

    • ul li
    • ul > li
    • ul + ul
    • ul ~ ul

    Example checklist:

    • ul li - Looking inside - Selects all the li elements placed (anywhere) inside the ul; Descendant selector
    • ul > li - Looking inside - Selects only the direct li elements of ul; i.e. it will only select direct children li of ul; Child Selector or Child combinator selector
    • ul + ul - Looking outside - Selects the ul immediately following the ul; It is not looking inside, but looking outside for the immediately following element; Adjacent Sibling Selector
    • ul ~ ul - Looking outside - Selects all the ul which follows the ul doesn't matter where it is, but both ul should be having the same parent; General Sibling Selector

    The one we are looking at here is General Sibling Selector

提交回复
热议问题