定义一个util.css的工具类,里面写上以下方法
$design-width: 1920;
@function trans($px) {
@return calc(100vw * #{$px} / #{$design-width});
}
全局引用此类
使用:
.layout-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 trans(20);
color: #ffffff;
height: trans(60);
background: $demo-success-black;
.icon {
display: flex;
align-items: center;
width: trans(160);
img {
width: trans(60);
height: trans(60);
border-radius: 50%;
}
.title {
margin-left: trans(15);
display: inline-block;
}
}
}