0

How to select siblings of another parent when input is focus?

Without js only css?

8th Dec 2020, 4:40 AM
Amar Dahake
1 Odpowiedź
+ 1
It isn't clear where this other parent is in relation to the focused input. If this other parent was a sibling to the selected input, you could use the ~ or + combinator. For example, input:focus + p { color: red; font-weight: bold; } That would select the paragraph immediately after the focused input so something like this: <input> <p>This will go red when the above input is in focus.</p> ~ is for general siblings instead of immediate next siblings. If this doesn't involve siblings, I think you'll need to use JavaScript. I don't know of a way to combine the existence of some element in the document with a completely independent CSS selector.
10th Dec 2020, 12:11 PM
Josh Greig
Josh Greig - avatar