zl程序教程

您现在的位置是:首页 >  前端

当前栏目

[CSS] Conditionally Assign Style to a Parent Element with Focus-Within Pseudo-class

CSS to with Class Element Style Parent focus
2023-09-14 08:59:14 时间

Use the focus-within pseudo-class to conditionally assign styling to a parent element when its child receives focus.

HTML:

import "./styles.css";

document.getElementById("app").innerHTML = `
<ul id="red">
  <li>
    <input value="Red">
  </li>
</ul>
`;

 

CSS:

#red:focus-within {
  background-color: red;
}