示例工程 42-logical-properties
42-logical-properties/app/index.html
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>逻辑属性</title>
<link rel="stylesheet" href="tokens.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="app">
<header class="site-header">
<span class="brand">LOGICAL LAB</span>
<nav aria-label="页面导航">
<a href="#flow">inline / block</a>
<a href="#inset">定位</a>
<a href="#writing">书写模式</a>
<a href="#notes">注意</a>
</nav>
</header>
<main class="page">
<p class="eyebrow">LESSON / 42</p>
<h1>逻辑属性:跟着文字方向走</h1>
<p class="lead">
用 inline-start 代替 left,用 block-end 代替 bottom;同一份 CSS 在 LTR、RTL 与竖排下都成立。
</p>
<section class="panel" id="flow">
<h2>1. inline 与 block</h2>
<p>两个盒子内容相同,只有 dir 不同;padding 与边框自动换边。</p>
<div class="compare">
<div class="box" dir="ltr">
<span class="pill">LTR</span>
<h3>从左到右</h3>
<p>padding-inline-start 在左边。</p>
</div>
<div class="box" dir="rtl">
<span class="pill">RTL</span>
<h3>从右到左</h3>
<p>padding-inline-start 在右边。</p>
</div>
</div>
</section>
<section class="panel" id="inset">
<h2>2. 逻辑定位</h2>
<p>关闭按钮用 inset-inline-end / inset-block-start,不写 left / right。</p>
<div class="callout" dir="ltr">
<span class="callout-tag">LTR</span>
<p>提示条:强调边在左侧。</p>
<button class="close" type="button" aria-label="关闭">×</button>
</div>
<div class="callout" dir="rtl">
<span class="callout-tag">RTL</span>
<p>提示条:强调边自动换到右侧。</p>
<button class="close" type="button" aria-label="关闭">×</button>
</div>
</section>
<section class="panel" id="writing">
<h2>3. 书写模式</h2>
<p>竖排时 inline 轴变成纵向,inline-size 控制的是高度。</p>
<div class="vertical-wrap">
<div class="vertical" dir="ltr">
<span class="vertical-tag">VERTICAL-RL</span>
<p>竖排文字,逻辑属性仍然生效。</p>
</div>
</div>
</section>
<section class="panel" id="notes">
<h2>4. 注意</h2>
<ul class="notes">
<li><code>inline-size</code> 对应文字方向上的宽度,不是物理 width。</li>
<li><code>margin-inline</code> 是左右两边的简写,<code>margin-block</code> 是上下。</li>
<li><code>inset-inline-start</code> 在 RTL 下等于 <code>right</code>。</li>
<li>逻辑属性不能与 <code>left</code> / <code>right</code> 混用而不自知;后写的会覆盖。</li>
</ul>
</section>
</main>
<footer class="site-footer">
<p>示例数据,仅用于教程演示。</p>
<p>LOGICAL PROPERTIES · 2026</p>
</footer>
</div>
</body>
</html>