<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> #my-button:focus-within { color: red; } </style> </head> <body> <button id="my-button" tabindex="0">item2</button> </body> </html>
When pressed, the color should switch to red. Works in Chrome and Firefox, always has issues with Safari (tested on version 15.6.1).
But what is the problem?
It seems :focus-within cannot be applied to buttons in Safari. But this works: