css使用details标签实现水平折叠面板效果代码
代码语言:html
所属分类:布局界面
代码描述:css使用details标签实现水平折叠面板效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @supports selector(::details-content) { .warning { display: none; } } .accordion-wrapper { display: flex; flex-direction: row; gap: 1rem; width: min-content; margin: 0 auto; } details { display: flex; flex-direction: row; background: transparent; color: white; height: 30rem; border-radius: 2rem; overflow: hidden; /* To make the image work …*/ position: relative; z-index: 1; /* Hide marker */ ::marker { content: ''; } /* The image is tucked in the summary, because otherwise it would be hidden when not [open] as it ends up in the ::details-content pseudo */ summary img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; z-index: -1; transition: filter 0.5s ease; } /* Animate the image */ &[open] summary img { filter: brightness(0.5); } summary { padding: 1rem 1em; width: 5rem; flex-shrink: 0; /* Prevent shrinking */ text-align: center; span { display: grid; place-content: center; width: 100%; aspect-ratio: 1; border-radius: 50%; background: rgb(0 0 0 / 0.25); } &:focus { outline: none; } } .details-content-wrapper { padding: 1.5rem 1em; width: 300px; } &:hover, &:has(summary:focus) { outline: 3px solid cadetblue; outline-offset: 3px; } } .details-content-wrapper { /* We need margin-trim … */ :first-child { margin-top: 0; } :last-child { margin-bottom: 0; } /* Animate-in the text when open */ p { transform: translateY(2rem); opacity: 0; transition: all 0.5s ease; transition-delay: 0.5s; } [open] & p { transform: none; opacity: 1; transition-delay: 0.5s; } } @layer reset { * { margin: 0; padding: 0; box-sizing: border-box; } html, body { height: 100%; } html { font-size: 14px; } } @layer baselayout { html { color: #444; font-family: system-ui; line-height: 1.42; overscroll-behavior-x: none; overflow: auto; } main { max-width: 90ch; margin: 0 auto; padding-bottom: 10rem; } p { margin-bottom: 1em; } h1, h2 { margin: 4em 0 1em; } h3 { margin: 1em 0 0.5em; } #demo { padding: 1em; border: 1px solid #ccc; background: #f4f6f9; } } @layer code { pre { border: 1px solid #dedede; padding: 1em; background: #f7f7f7; font-family: "Courier 10 Pitch", Courier, monospace; overflow-x: auto; border-left: 0.4em solid cornflowerblue; tab-size: 4; } code:not(pre code) { background: #f7f7f7; border: 1px solid rgb(0 0 0 / 0.2); padding: 0.1rem 0.3rem; margin: 0.1rem 0; border-radius: 0.2rem; /* display: inline-block; */ -webkit-box-decoration-break: clone; white-space: pre-wrap; } } @layer warning { .warning { box-sizing: border-box; padding: 1em; margin: 1em 0; border: 1px solid #ccc; background: rgba(255 255 205 / 0.8); } .warning > :first-child { margin-top: 0; } .warning > :last-child { margin-bottom: 0; } .warning a { color: blue; } .warning--info { border: 1px solid #123456; background: rgb(205 230 255 / 0.8); } .warning--alarm { border: 1px solid red; background: #ff000010; } } /* Hide a bunch of stuff when embedded */ :root[data-embed="yep"] { main { padding: 2em 1em; :not(p.warning, p.warning *, #demo, #demo *, #demo ~ p, #demo ~ p *) { display: none; } } #demo ~ p { margin-top: 1em; text-align: center; } } </style> </head> <body translate="no"> <script> document.documentElement.dataset.embed = window.location.search.includes('type=embed') ? "yep" : "nope"; </script> <main> <h1>Styling <code><details></code>: Horizontal Accordion <em>(no animation)</em></h1> &.........完整代码请登录后点击上方下载按钮下载查看
网友评论0