首先声明一点,transform: scale对行内元素无效,而对块级元素和原子行内级元素生效等。
在开发中,有时会因满足设计需要而对元素进行整体缩放,transform: scale是现代浏览器都支持的css元素,应该是首选,但它会引发一个问题,虽然可以缩小整体显示的内容,但是并没有引起重排,所以占据的实际空间没有缩小,具体看下面的代码以及图片。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>使用scale缩小之后实际空间没有减小的问题解决</title>
<style type="text/css">
i {
font-style: normal;
}
.container {
margin: 100px auto;
display: flex;
align-items: center;
justify-content: center;
min-width: 140px;
padding: 5px 10px 7px;
display: inline-block;
height: 48px;
line-height: 48px;
padding: 0 10px;
text-align: center;
color: #fff;
background: linear-gradient(270deg, rgba(237,8,2,1) 0%,rgba(253,82,22,1) 100%);
border-radius: 30px;
}
.b {
font-size: 24px;
font-family: PingFangSC-Regular;
line-height: 33px;
height: 33px;
}
.price {
line-height: 33px;
height: 33px;
font-size: 32px;
font-weight: 700;
display: inline-block;/*transform对行内元素不生效*/
transform-origin: bottom right;
transform: scale(.7);
margin-left: -6px;
}
</style>
</head>
<body>
<span class="container">
<i class="b">B</i>
<i class="price">3920.00</i>
</span>
</body>
</html>


解决方案:
(1)若不要红色按钮中的内容水平居中,可将transform-origin的值改为bottom left,即改变变化原点;
(2) 若是居中显示,可使用zoom,即将transform: scale(.7); transform-origin: right;替换为zoom: .7,zoom元素可以缩小实际所占空间,原为IE浏览器才支持的元素,现在Chrome和Safria也支持了