Skip to content

CSS: modal

.instui-modal — 一个对话框表面(适用于原生 <dialog>);包含 header/body/footer 部分。

参见成员 modal.headermodal.bodymodal.footer 以获取各个部分。

Source: body.css

TIP

JS 增强 — 该组件的 CSS 可独立渲染与工作;将其与 @pantoken/interactions 配对可添加交互行为。参见下方的 modifier table

无障碍

使用 showModal() 打开原生 <dialog> 以获得模态语义和按 Esc 关闭的行为,并使用指向 .headeraria-labelledby 为其命名。

用法

css
@import "@pantoken/components/components.css";
@import "@pantoken/components/modal.css";

演示

示例

html
<dialog class="instui-modal -size-sm" id="modal-sm">
  <div class="header"><strong>Small</strong></div>
  <div class="body"><code>-size-sm</code> — a narrow modal.</div>
  <div class="footer">
    <button class="instui-button">Close</button>
  </div>
</dialog>

结构

text
.instui-modal
  modal.header (component)
  modal.body (component)
  modal.footer (component)
flowchart TD n0[".instui-modal"]:::cssdoc-root n1(["modal.header"]):::cssdoc-component n2(["modal.body"]):::cssdoc-component n3(["modal.footer"]):::cssdoc-component n0 --> n1 n0 --> n2 n0 --> n3 click n1 "/api/css/modal.header.md" click n2 "/api/css/modal.body.md" click n3 "/api/css/modal.footer.md" classDef cssdoc-root stroke-width:1px; classDef cssdoc-part stroke-width:1px; classDef cssdoc-slot stroke-width:1px; classDef cssdoc-component stroke-width:1px;

修饰符

修饰符描述
.-blur模态框后面的背景应用模糊效果。
.-color-inverse暗色(配合媒体主体使用)。@affects modal.header @affects modal.body @affects modal.footer — 为每个部分着色以呈现暗色外观。
.-density-compact缩紧各部分的内边距。@affects modal.header @affects modal.body @affects modal.footer — 收紧每个部分的填充。
.-overflow-fit限制在视口内并使主体可滚动。@affects modal.body — 当模态框被限制在视口时使主体可滚动。
.-size-auto按内容尺寸自适应。
.-size-fullscreen边到边。
.-size-large一个宽型模态框。为 -size-lg 的长格式别名。
.-size-lg一个宽型模态框。
.-size-sm一个窄型模态框。
.-size-small一个窄型模态框。为 -size-sm 的长格式别名。

伪元素

伪元素描述
::backdrop将对话框后方的页面变暗作为其遮罩,并在 -blur 下对其进行毛玻璃处理。

消耗代币

Token类型
--instui-component-mask-background-color<color>LightDarklight-dark(rgba(255,255,255,0.75), rgba(28,34,43,0.75))
--instui-component-modal-auto-min-width<length>16em
--instui-component-modal-background-color<color>LightDarklight-dark(#ffffff, #171B21)
--instui-component-modal-border-color<color>LightDarklight-dark(#E8EAEC, #334450)
--instui-component-modal-border-radius<length>1rem
--instui-component-modal-border-width<length>0.0625rem
--instui-component-modal-font-family[ <font-family-name> | <generic-font-family> ]#Atkinson Hyperlegible Next, "Helvetica Neue", Helvetica, Arial, sans-serif
--instui-component-modal-inverse-background-color<color>LightDarklight-dark(#273540, #1C222B)
--instui-component-modal-inverse-border-color<color>#334450
--instui-component-modal-inverse-text-color<color>#ffffff
--instui-component-modal-large-max-width<length>62em
--instui-component-modal-medium-max-width<length>48em
--instui-component-modal-small-max-width<length>30em
--instui-component-modal-text-color<color>LightDarklight-dark(#273540, #F2F4F5)
--instui-elevation-topmostnone | <shadow>#
--instui-spacing-space-xl<length>1.5rem

浏览器支持

  • 为原生 <dialog> 及其 ::backdrop 添加样式;顶层渲染和背景样式需要浏览器支持 dialog 元素。

子组件

相关

  • tray — tray 是相同的可关闭覆盖模式,但固定在屏幕边缘。