首页 > web前端 > css教程 > 在开放的细节元素上放置背景

在开放的细节元素上放置背景

Jennifer Aniston
发布: 2025-03-23 09:39:10
原创
274 人浏览过

Put a Background on Open Details Elements

One thing that can be just a smidge funky about the

element is that, when open, it’s not always 100% clear what is inside that element and what isn’t. I’m not saying that always matters or that it’s a particularly hard problem to solve, I’m just noting it as it came up recently for me.

Here’s a visual example:

The solution is… CSS. Style the

somewhat uniquely, and that problem goes away. Even if you want the typography to be the same, or you don’t want any exclusive styling until the
is opened, it’s still possible. Using an alpha-transparent fill, you can even make sure that deeper-nested
remain clear.

Here’s that CSS:

details[open] {
  --bg: rgb(0 0 0 / 0.2);
  background: var(--bg);
  outline: 1rem solid var(--bg);
  margin: 0 0 2rem 0;
}
登录后复制

And the demo:

以上是在开放的细节元素上放置背景的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板