CSS-Selector for multiple elements

前端 未结 2 1578
萌比男神i
萌比男神i 2020-12-12 02:01

I am not at all getting how to use more advanced css-selectors like + or > But as I am now needing it to prevent too much JS, maybe someone can help me out with this particu

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-12 02:48

    Just add the selector for the button, separated with a comma:

    .rf_re1-suche_container input:focus,
    .rf_re1-suche_container input:focus ~ button {
        background: orange;
    }
    

    The tilde (~) is the general sibling selector. It selects the element ONLY if it is preceded by the element before the sibling.

    This is by the way quite similar to the adjacent sibling selector, but with the latter the two elements need to be right behind eachother. In your case it doesn't really matter, as these two elements are the only one in the parent.

提交回复
热议问题