Safari does not support the :focus-within pseudo-class
P粉561438407
P粉561438407 2023-09-14 13:30:52
0
1
536

<!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?

P粉561438407
P粉561438407

reply all(1)
P粉141911244

It seems :focus-within cannot be applied to buttons in Safari. But this works:

<!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-li:focus-within > #my-button {
      color: red;
    }
  </style>
</head>
<body>
  <ul>
    <li id="my-li" tabindex="0">
      <button id="my-button">item2</button>
    </li>
  </ul>
</body>
</html>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!