--- title: scale slug: Web/CSS/scale tags: - CSS - transform translation_of: Web/CSS/scale ---
CSS属性 scale 允许你可以分别且独立地指定CSS属性 {{CSSxRef("transform")}} 缩放的比例。这更好地映射到典型的UI(用户界面)用法中,并免去了在指定变换值时必须记住变换函数的精确顺序的麻烦。
/* 关键值 */ scale: none; /* 单个值 */ /* 设定比1大的数值使该元素变大 */ scale: 2; /* 设定比1小的数值使该元素缩小 */ scale: 0.5; /* 两个值 */ scale: 2 0.5; /* 三个值 */ scale: 2 0.5 2;
none<div> <p class="scale">Scaling</p> </div>
* {
box-sizing: border-box;
}
html {
font-family: sans-serif;
}
div {
width: 150px;
margin: 0 auto;
}
p {
padding: 10px 5px;
border: 3px solid black;
border-radius: 20px;
width: 150px;
font-size: 1.2rem;
text-align: center;
}
.scale {
transition: scale 1s;
}
div:hover .scale {
scale: 2 0.7;
}
{{EmbedLiveSample("Examples")}}
| 规范 | 状态 | 备注 |
|---|---|---|
| {{SpecName("CSS Transforms 2", "#individual-transforms", "individual transforms")}} | {{Spec2("CSS Transforms 2")}} | Initial definition. |
{{CSSInfo}}
{{Compat("css.properties.scale")}}