导航

v2.1.0
网站页面

居中布局

在视口中央呈现一项任务,例如登录或错误页面,可搭配侧面板。

居中布局只在视口中央呈现一项任务,例如登录、确认地址或显示错误页面。框架采用页面框架,因此以 dvh 计与视口等高;两个工具类将其中的内容居中。

居中布局

<main class="page items-center justify-center p-lg bg-surface-tray fg-text-body text-sm">  <form class="sheet form w-full max-w(380) p-xl">    <header class="flex flex-col gap-3xs">      <h1 class="heading heading-lg">Sign in to Atlas</h1>      <p class="m(0) fg-text-muted">Welcome back.</p>    </header>    <label class="field">      Email<input class="input" type="email" name="email" autocomplete="username" placeholder="you@example.com" required>    </label>    <label class="field">      Password<input class="input" type="password" name="password" autocomplete="current-password" required>    </label>    <button class="btn btn-primary">Sign in</button>    <p class="m(0) text-center fg-text-muted">      New here? <a class="link" href="#">Create an account</a>    </p>  </form></main>
<main className="page items-center justify-center p-lg bg-surface-tray fg-text-body text-sm">  <form className="sheet form w-full max-w(380) p-xl">    <header className="flex flex-col gap-3xs">      <h1 className="heading heading-lg">Sign in to Atlas</h1>      <p className="m(0) fg-text-muted">Welcome back.</p>    </header>    <label className="field">      Email<input className="input" type="email" name="email" autoComplete="username" placeholder="you@example.com" required />    </label>    <label className="field">      Password<input className="input" type="password" name="password" autoComplete="current-password" required />    </label>    <button className="btn btn-primary">Sign in</button>    <p className="m(0) text-center fg-text-muted">      New here? <a className="link" href="#">Create an account</a>    </p>  </form></main>
<main class="page items-center justify-center p-lg bg-surface-tray fg-text-body text-sm">  <form class="sheet form w-full max-w(380) p-xl">    <header class="flex flex-col gap-3xs">      <h1 class="heading heading-lg">Sign in to Atlas</h1>      <p class="m(0) fg-text-muted">Welcome back.</p>    </header>    <label class="field">      Email<input class="input" type="email" name="email" autocomplete="username" placeholder="you@example.com" required>    </label>    <label class="field">      Password<input class="input" type="password" name="password" autocomplete="current-password" required>    </label>    <button class="btn btn-primary">Sign in</button>    <p class="m(0) text-center fg-text-muted">      New here? <a class="link" href="#">Create an account</a>    </p>  </form></main>
<template>  <main class="page items-center justify-center p-lg bg-surface-tray fg-text-body text-sm">    <form class="sheet form w-full max-w(380) p-xl">      <header class="flex flex-col gap-3xs">        <h1 class="heading heading-lg">Sign in to Atlas</h1>        <p class="m(0) fg-text-muted">Welcome back.</p>      </header>      <label class="field">        Email<input class="input" type="email" name="email" autocomplete="username" placeholder="you@example.com" required>      </label>      <label class="field">        Password<input class="input" type="password" name="password" autocomplete="current-password" required>      </label>      <button class="btn btn-primary">Sign in</button>      <p class="m(0) text-center fg-text-muted">        New here? <a class="link" href="#">Create an account</a>      </p>    </form>  </main></template>

#实现方式

  • page items-center justify-center。 单个任务占据整页,因此直接在 <main> 上设置纵向布局,最小高度与视口等高,再用两个工具类让内容在两个轴上居中。p-lg 让卡片与手机屏幕边缘留出间距。
  • 在卡片上使用 w-full max-w(380)。 卡片在手机上占满可用宽度,最大宽度以单列字段易于阅读和填写为准。
  • 凸起面板下方的托盘。 页面框架使用 bg-surface-tray,卡片采用凸起面板材质,整页只有卡片凸起。
  • 卡片高于视口时,页面可以滚动。 页面只设最小高度,不固定高度,因此可以随内容增高。手机弹出键盘时就会出现这种情况。

卡片同时也是表单,由表单设置字段间距。

#带侧面板的布局

从 md 断点起,页面框架分为等宽两列,一列放任务,另一列放展示品牌、引文或图片的面板。低于该断点时,面板隐藏,页面只保留任务。

带侧面板的布局

<div class="page bg-surface-base fg-text-body text-sm">  <div class="grow(1) grid grid-cols(2)@md">    <main class="flex items-center justify-center p-lg">      <form class="form w-full max-w(340)">        <header class="flex flex-col gap-3xs">          <h1 class="heading heading-lg">Sign in to Atlas</h1>          <p class="m(0) fg-text-muted">Welcome back.</p>        </header>        <label class="field">          Email<input class="input" type="email" name="email" autocomplete="username" placeholder="you@example.com" required>        </label>        <label class="field">          Password<input class="input" type="password" name="password" autocomplete="current-password" required>        </label>        <button class="btn btn-primary">Sign in</button>        <p class="m(0) text-center fg-text-muted">          New here? <a class="link" href="#">Create an account</a>        </p>      </form>    </main>    <aside class="hidden flex@md flex-col justify-between p-2xl bg-surface-inverse fg-text-inverse">      <p class="m(0) flex items-center gap-xs text-md font-medium">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <circle cx="8" cy="8" r="6" /><path d="M8 4.3333A3.6667 3.6667 0 0 1 8 11.6667Z" fill="currentColor" stroke="none" />        </svg>Atlas      </p>      <figure class="m(0) flex flex-col gap-md max-w(440)">        <blockquote class="m(0)">          <p class="m(0) text-2xl">            We replaced four libraries with a stylesheet, and the interface got quieter.          </p>        </blockquote>        <figcaption class="flex items-center gap-sm text-sm">          <span class="avatar" aria-hidden="true">            <img class="avatar-image" src="/demo/people/seoyeon-kim.webp" alt width="32" height="32"><span class="avatar-fallback">SK</span>          </span>Seo-yeon Kim, Engineering at Orbit        </figcaption>      </figure>    </aside>  </div></div>
import ContrastIcon from '@master/icons-react/native/16/soft/contrast'<div className="page bg-surface-base fg-text-body text-sm">  <div className="grow(1) grid grid-cols(2)@md">    <main className="flex items-center justify-center p-lg">      <form className="form w-full max-w(340)">        <header className="flex flex-col gap-3xs">          <h1 className="heading heading-lg">Sign in to Atlas</h1>          <p className="m(0) fg-text-muted">Welcome back.</p>        </header>        <label className="field">          Email<input className="input" type="email" name="email" autoComplete="username" placeholder="you@example.com" required />        </label>        <label className="field">          Password<input className="input" type="password" name="password" autoComplete="current-password" required />        </label>        <button className="btn btn-primary">Sign in</button>        <p className="m(0) text-center fg-text-muted">          New here? <a className="link" href="#">Create an account</a>        </p>      </form>    </main>    <aside className="hidden flex@md flex-col justify-between p-2xl bg-surface-inverse fg-text-inverse">      <p className="m(0) flex items-center gap-xs text-md font-medium">        <ContrastIcon className="icon" />Atlas      </p>      <figure className="m(0) flex flex-col gap-md max-w(440)">        <blockquote className="m(0)">          <p className="m(0) text-2xl">            We replaced four libraries with a stylesheet, and the interface got quieter.          </p>        </blockquote>        <figcaption className="flex items-center gap-sm text-sm">          <span className="avatar" aria-hidden="true">            <img className="avatar-image" src="/demo/people/seoyeon-kim.webp" alt="" width="32" height="32" /><span className="avatar-fallback">SK</span>          </span>Seo-yeon Kim, Engineering at Orbit        </figcaption>      </figure>    </aside>  </div></div>
<script>  import ContrastIcon from '@master/icons-svelte/native/16/soft/contrast'</script><div class="page bg-surface-base fg-text-body text-sm">  <div class="grow(1) grid grid-cols(2)@md">    <main class="flex items-center justify-center p-lg">      <form class="form w-full max-w(340)">        <header class="flex flex-col gap-3xs">          <h1 class="heading heading-lg">Sign in to Atlas</h1>          <p class="m(0) fg-text-muted">Welcome back.</p>        </header>        <label class="field">          Email<input class="input" type="email" name="email" autocomplete="username" placeholder="you@example.com" required>        </label>        <label class="field">          Password<input class="input" type="password" name="password" autocomplete="current-password" required>        </label>        <button class="btn btn-primary">Sign in</button>        <p class="m(0) text-center fg-text-muted">          New here? <a class="link" href="#">Create an account</a>        </p>      </form>    </main>    <aside class="hidden flex@md flex-col justify-between p-2xl bg-surface-inverse fg-text-inverse">      <p class="m(0) flex items-center gap-xs text-md font-medium">        <ContrastIcon class="icon" />Atlas      </p>      <figure class="m(0) flex flex-col gap-md max-w(440)">        <blockquote class="m(0)">          <p class="m(0) text-2xl">            We replaced four libraries with a stylesheet, and the interface got quieter.          </p>        </blockquote>        <figcaption class="flex items-center gap-sm text-sm">          <span class="avatar" aria-hidden="true">            <img class="avatar-image" src="/demo/people/seoyeon-kim.webp" alt width="32" height="32"><span class="avatar-fallback">SK</span>          </span>Seo-yeon Kim, Engineering at Orbit        </figcaption>      </figure>    </aside>  </div></div>
<script setup>import ContrastIcon from '@master/icons-vue/native/16/soft/contrast'</script><template>  <div class="page bg-surface-base fg-text-body text-sm">    <div class="grow(1) grid grid-cols(2)@md">      <main class="flex items-center justify-center p-lg">        <form class="form w-full max-w(340)">          <header class="flex flex-col gap-3xs">            <h1 class="heading heading-lg">Sign in to Atlas</h1>            <p class="m(0) fg-text-muted">Welcome back.</p>          </header>          <label class="field">            Email<input class="input" type="email" name="email" autocomplete="username" placeholder="you@example.com" required>          </label>          <label class="field">            Password<input class="input" type="password" name="password" autocomplete="current-password" required>          </label>          <button class="btn btn-primary">Sign in</button>          <p class="m(0) text-center fg-text-muted">            New here? <a class="link" href="#">Create an account</a>          </p>        </form>      </main>      <aside class="hidden flex@md flex-col justify-between p-2xl bg-surface-inverse fg-text-inverse">        <p class="m(0) flex items-center gap-xs text-md font-medium">          <ContrastIcon class="icon" />Atlas        </p>        <figure class="m(0) flex flex-col gap-md max-w(440)">          <blockquote class="m(0)">            <p class="m(0) text-2xl">              We replaced four libraries with a stylesheet, and the interface got quieter.            </p>          </blockquote>          <figcaption class="flex items-center gap-sm text-sm">            <span class="avatar" aria-hidden="true">              <img class="avatar-image" src="/demo/people/seoyeon-kim.webp" alt width="32" height="32"><span class="avatar-fallback">SK</span>            </span>Seo-yeon Kim, Engineering at Orbit          </figcaption>        </figure>      </aside>    </div>  </div></template>
在平板和手机视图中,面板隐藏,页面只保留表单。

grid grid-cols(2)@md 将页面框架分为两列,面板使用 hidden flex@md。页面框架对应整个视口,因此这里的 @md 断点按视口宽度判断,无需使用容器查询。

面板采用墨色,由 bg-surface-inverse 搭配 fg-text-inverse。面板会最先隐藏,因此只放几句话,读者必需的信息应放在页面的其他位置。

#可以用它构建的页面

身份验证页面和各种独立页面,都是这个框架换上另一张卡片。

页面卡片中的内容
登录、注册登录区块:它的第一张卡片,或注册卡片
验证同一区块的验证码卡片,内含验证码输入框
忘记密码重置密码区块的两张卡片
未找到、出错、维护中空状态区块,说明发生了什么,并提供一个继续的入口

包含多个步骤的任务(例如创建工作区)有自己的页面:多步骤任务。

#无障碍

  • 整页只有一个 <h1>,位于卡片内。
  • 面板使用 <aside>。仅包含装饰时,用 aria-hidden="true" 将它从辅助技术中隐藏;包含引文时,它属于正文内容,对辅助技术保持可见。
  • 为字段设置 autocomplete 值,让密码管理器能够自动填充。