Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h2>CSS Toggles based slide (Pure CSS)</h2>

<div class="alert">Your browser does not support CSS Toggles, please upgrade to Chrome Canary 108+ and turn on Flag(`--enable-blink-features=CSSToggles`).</div>

<section>
  <div class="control">
    <div class="btn prev-slide" title="上一页">
      <svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
        <path d="M729.6 931.2l-416-425.6 416-416c9.6-9.6 9.6-25.6 0-35.2-9.6-9.6-25.6-9.6-35.2 0l-432 435.2c-9.6 9.6-9.6 25.6 0 35.2l432 441.6c9.6 9.6 25.6 9.6 35.2 0C739.2 956.8 739.2 940.8 729.6 931.2z" p-id="10915"></path>
      </svg>
    </div>
    <div class="btn next-slide" title="下一页">
      <svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
        <path d="M761.6 489.6l-432-435.2c-9.6-9.6-25.6-9.6-35.2 0-9.6 9.6-9.6 25.6 0 35.2l416 416-416 425.6c-9.6 9.6-9.6 25.6 0 35.2s25.6 9.6 35.2 0l432-441.6C771.2 515.2 771.2 499.2 761.6 489.6z" p-id="10760"></path>
      </svg>
    </div>
  </div>

  <div class="slide-content">
    <article>
      <div class="tips"></div>
      <img src="https://wx3.sinaimg.cn/mw690/90f78f62ly1fm3yd7emocj213i0qon73.jpg" alt="" loading="lazy">
    </article>
    <article>
      <div class="tips"></div>
      <img src="https://wx4.sinaimg.cn/mw1024/90f78f62ly1fvqpameuuwj20qo0zi10d.jpg" alt="" loading="lazy">
    </article>
    <article>
      <div class="tips"></div>
      <img src="https://wx2.sinaimg.cn/mw690/90f78f62ly1fmls4xf4w2j21400qoafa.jpg" alt="" loading="lazy">
    </article>
  </div>

  <div class="pagination">
    <div class="number" style="toggle-trigger: slides set 1">1</div>
    <div class="number" style="toggle-trigger: slides set 2">2</div>
    <div class="number" style="toggle-trigger: slides set 3">3</div>
  </div>
</section>
              
            
!

CSS

              
                .alert {
  color: red;
  padding: 0 2em;
}

@supports (toggle-trigger: foo next) and (toggle-root: foo 3 at 1 cycle-on) {
  .alert {
    display: none;
  }
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
}

* {
  box-sizing: border-box;
}

img {
  max-width: 100%;
  display: block;
}

:root {
  --tips-size: 100px;
}

.btn {
  padding: 5px 10px;
  user-select: none;
  cursor: pointer;
}

section {
  margin-top: 20px;
  position: relative;
  width: 600px;
  aspect-ratio: 3 / 2;
  /* toggle-root: slides 3 at 1 sticky; */
  toggle-root: slides 3 at 1 cycle-on;
}

article {
  flex: 1 0 100%;
  transition: transform 0.3s ease-out;
  transform: translateX(var(--x, 0));
}

/* 第1页 */
article:nth-of-type(1):toggle(slides 1) {
  --x: 0%;
}

article:nth-of-type(1):toggle(slides 1) ~ article {
  --x: 0%;
}

article:nth-of-type(1):toggle(slides 2) {
  --x: -100%;
}

/* 第2页 */
article:nth-of-type(2):toggle(slides 2) {
  --x: -100%;
}

article:nth-of-type(2):toggle(slides 2) ~ article {
  --x: -100%;
}

/* 第3页 */
article:nth-of-type(3):toggle(slides 3),
article:nth-of-type(2):toggle(slides 3),
article:nth-of-type(1):toggle(slides 3) {
  --x: -200%;
}

/* 分页高亮 */
:toggle(slides 1) ~ .pagination .number:nth-of-type(1),
:toggle(slides 2) ~ .pagination .number:nth-of-type(2),
:toggle(slides 3) ~ .pagination .number:nth-of-type(3) {
  background-color: #fff;
  color: #333;
  transform: scale(1.3);
}

.next-slide {
  toggle-trigger: slides next;
}

.prev-slide {
  toggle-trigger: slides prev;
}

.slide-content {
  overflow: hidden;
  display: flex;
  width: 100%;
  aspect-ratio: 3 / 2;
  position: relative;
  border-radius: 10px;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3);
}

/* tips */
article {
  counter-increment: count;
  overflow: hidden;
}

.tips:before {
  content: counters(count, ".", decimal);
  width: calc(var(--tips-size) / 2.81408534);
  height: calc(var(--tips-size) / 2.81408534);
  pointer-events: none;
  display: flex;
  justify-content: center;
  transform: translate(140%, 140%) rotate(45deg);
  transform-origin: 0 0;
}

.tips {
  position: absolute;
  top: 0;
  transform: translate(-50%, -50%) rotate(-45deg);
  position: absolute;
  top: 0;
  left: 0;
  width: var(--tips-size);
  height: var(--tips-size);
  color: #fff;
  font-size: 30px;
  background: rgba(46, 50, 51, 0.8);
  transition: --tips-size 0.3s;
  white-space: nowrap;
}

/* 分页 */
.icon {
  width: 64px;
  height: 64px;
  fill: #fff;
  transition: background 0.3s;
  border-radius: 999px;
  padding: 6px 0;
}

.icon:hover {
  background-color: rgba(0, 0, 0, 0.5);
}

.control {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 9;
  width: 100%;
  display: flex;
  justify-content: space-between;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  user-select: none;
}

.pagination .number {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  color: transparent;
  background-color: transparent;
  transition: 0.3s;
  margin-right: 10px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid #fff;
  box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

              
            
!

JS

              
                // No JS

let root = document.querySelector("section");
console.log("Get toggles \n", root.toggles.get("slides"));

root.addEventListener(
  "togglechange",
  function (e) {
    console.log("CSS toggle changed \n", e);
  },
  false
);

              
            
!
999px

Console