全屏
<div class="overlay-toggle"><label>Transition overlay<input type=checkbox checked></label></div>

<div class="app">
  <h2>Account Actions</h2>
  <p>This might be a section in your preferences where you can take some actions on your account.</p>
  <h3>Delete account</h3>
  <p>Delete your account forever. This is the button you click to open the dialog in this demo.</p>
  <div class="actionbar">
    <button onclick="document.querySelector('dialog').showModal();">Delete</button>
  </div>
  <h3>Archive Account</h3>
  <p>Archive your account for now. Note: this is a demo, you can't click on this button.</p>
  <div class="actionbar">
    <button disabled>Archive</button>
  </div>
</div>

<dialog>
  <div class="top">
    <h2>Delete this user account</h2>
    <button class="close-btn" onclick="document.querySelector('dialog').close();">
     <p aria-hidden="true">❌</p>
     <p class="sr-only">Close dialog</p>
    </button>
  </div>
  <div class="dialog-text">
  <p>Warning: This is a destructive action.</p>
  <button id="anchor-btn" class="info-btn" popovertarget="my-tooltip">
    <p aria-hidden="true">?</p>
    <p class="sr-only">Open Tooltip</p>
  </button>
  </div>
  <form method="dialog">
    <button class="confirmation-btn">Confirm deletion</button>
  </form
</dialog>

<p id="my-tooltip" class="info-tooltip" anchor="anchor-btn" popover>"Destructive action" means that this cannot be undone. Do not open a ticket. You've been warned. Good luck.
</p>
/* Animation things */
[popover],
dialog,
::backdrop{
  opacity: 0;
  transition: opacity 1s, display 1s allow-discrete;
}

:popover-open,
[open],
[open]::backdrop {
  opacity: 1;
}

@starting-style {
  :popover-open,
  [open],
  [open]::backdrop {
    opacity: 0;
  }
}

.overlay, .overlay::backdrop {
  transition: opacity 1s, display 1s allow-discrete, overlay 1s allow-discrete;
}

::backdrop {
  background-color: rgba(0,0,0,.6);
}

/* ETC */

dialog {
  background: linear-gradient(white, white 3.5rem, #f6f6f6 3.5rem);
  border: 1px solid lightgray;
  border-radius: 1rem;
  padding: 1rem;
  min-width: 300px;
}

.dialog-text {
  display: flex;
  line-height: 0;
  margin-bottom: 2rem;
}

.confirmation-btn {
  display: block;
  background: white;
  color: red;
  border: 1px solid red;
  padding: 0.5rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  transition-duration: 0.25s;
  
  &:hover {
    background: red;
    color: white;
  }
}

.close-btn {
  position: absolute;
  top: 0.1rem;
  right: 0.6rem;
  border: 0;
  background: none;
  filter: grayscale(1);
}

.info-tooltip {
  --spacer: 0.25rem;
  position-fallback: --top-then-bottom;
  translate: -50% 0;
  font-size: 90%;
  background: #222;
  color: white;
  border: none;
  padding: 1rem;
  max-width: 200px;
}

@position-fallback --top-then-bottom {
  @try {
    bottom: calc(anchor(top) + var(--spacer));
    left: anchor(center);
  }

  @try {
    top: calc(anchor(bottom) + var(--spacer));
    left: anchor(center);
  }
}

dialog h2 {
  margin: 0 0 2rem;
}

.info-btn {
  background: #ddd;
  font-size: 0.9rem;
  font-weight: 800;
  font-family: monospace;
  border-radius: 1.2rem;
  height: 1.2rem;
  width: 1.2rem;
  display: grid;
  place-content: center;
  border: 2px solid black;
  transition-duration: 0.25s;
  
  &:hover {
    background-color: gray;
    color: white;
  }
}

body {
  font-family: system-ui, serif;
  line-height: 1.4;
  margin: 0;
}

button {
  text-transform: uppercase;
}

h2 {
  line-height: 1;
}

.sr-only {
  clip: rect(0 0 0 0); 
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap; 
  width: 1px;
}

.overlay-toggle {
  position: fixed;
  top: 0;
  width: 100%;
  background: aliceblue;
  font-weight: 700;
  padding: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.app {
  margin: 4rem auto 0;
  padding: 1rem 3rem 2rem;
  border: 1px solid lightgray;
  border-radius:  1rem;
  width: clamp(200px, 60vw, 500px);
}

.actionbar > button {
  border: 1px solid gray;
  background: white;
  padding: 0.5rem;
  
  :is(disabled) {
    border-color: lightgray;
  }
}
const checkbox = document.querySelector('input');

const updatecheckbox = () => {
  document.querySelectorAll('[popover], dialog').forEach(elem => {
    if (checkbox.checked) {
      elem.classList.add('overlay');
    } else {
      elem.classList.remove('overlay');
    }
  });
};
updatecheckbox();
checkbox.onchange = updatecheckbox;
返回