示例工程 22-mobile-first
22-mobile-first/demo-02-order/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>min-width 的顺序</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>min-width 的顺序</h1>
<p>在 760px 以上,正确组是紫色,错误组仍是蓝色。</p>
<section class="pane">
<h2>正确:480 → 760</h2>
<div class="boxes correct">
<div class="box">480 起变蓝</div>
<div class="box">760 起变紫</div>
</div>
</section>
<section class="pane">
<h2>错误:760 → 480</h2>
<div class="boxes wrong">
<div class="box">760 起变紫</div>
<div class="box">480 起变蓝(后写覆盖)</div>
</div>
</section>
<pre><code>/* 正确 */
@media (min-width: 480px) { .box { background: #2563eb; } }
@media (min-width: 760px) { .box { background: #7c3aed; } }
/* 错误:宽范围写在后面,760 以上会退回蓝色 */
@media (min-width: 760px) { .box { background: #7c3aed; } }
@media (min-width: 480px) { .box { background: #2563eb; } }</code></pre>
</body>
</html>