Select first occurring element after another element

后端 未结 5 1487
时光取名叫无心
时光取名叫无心 2020-12-01 03:33

I\'ve got the following HTML code on a page:

Some text

Some more text!

In my .css I\

5条回答
  •  [愿得一人]
    2020-12-01 04:05

    For your literal example you'd want to use the adjacent selector (+).

    h4 + p {color:red}//any 

    that is immediately preceded by an

    Some text

    I'm red

    I'm not

    However, if you wanted to select all successive paragraphs, you'd need to use the general sibling selector (~).

    h4 ~ p {color:red}//any 

    that has the same parent as, and comes after an

    Some text

    I'm red

    I am too

    It's known to be buggy in IE 7+ unfortunately.

提交回复
热议问题