<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
:root {
--blue: #1e90ff;
--white: #ffffff;
}
.container {
--fontsize: 25px;
}
body {
background-color: var(--blue);
}
h2 {
border-bottom: 2px solid var(--blue);
}
.container {
color: var(--blue);
background-color: var(--white);
padding: 15px;
font-size: var(--fontsize);
}
@media screen and (min-width: 450px) {
.container {
--fontsize: 50px;
}
:root {
--blue: lightblue;
}
}
</style>
</head>
<body>
<h1>在媒体查询中使用变量</h1>
<div class="container">
<h2>Welcome to Shanghai!</h2>
<p>当浏览器的宽度为 450px 或更宽时,将 --fontsize 变量值设置为 50px,将 --blue 变量值设置为 lightblue。请调整浏览器窗口的大小以查看效果。</p>
</div>
</body>
</html>